天梯赛
前言
1-20
1001 害死人不偿命的(3n+1)猜想
n = int(input())
res = 0
while n!=1:
if n%2==0:
n=n/2
else:
n=(3*n+1)/2
res+=1
print(res)
1002 写出这个数
n = input()
number=["ling","yi","er","san","si","wu","liu","qi","ba","jiu"]
num =0
for i in n:
num = num+int(i)
num = str(num)
res =[]
for index in num:
res.append(number[int(index)])
print(" ".join(res))
1003 我要通过!
1.条件1就没什么说的,注意不要有非法字符,可以用一个计数器专门记录非法字符,一旦有就是NO。
2.在条件1的基础上,条件2说的是P之前的空字符或者A的数量要等于T之后的空字符或者A字母数量,由于这里P和T只出现一次,因此if判断找到这两个P、T字母之后计算前后数量相等就可以了。
3.条件三说的是P左边一个,PT中间两个,T之后两个。因此条件2三综合就是P左边的A或者空字符数量乘PT中间的数量等于T右边的数量。
n = int(input())
def Solve(input_str):
num_of_P = input_str.count('P')
local_of_P = input_str.find('P')
num_of_T = input_str.count('T')
local_of_T = input_str.find('T')
num_of_A = input_str.count('A')
if num_of_P != 1 or num_of_T !=1 or len(input_string) != num_of_P+num_of_A+num_of_T or local_of_T-local_of_P <=1:
print('NO')
elif local_of_P*(local_of_T-local_of_P-1)==len(input_string)-local_of_T-1:
print('YES')
else:
print('NO')
for i in range(n):
input_string = str(input())
Solve(input_string)
1004 成绩排名
n = int(input())
students = []
for _ in range(n):
name, student_id,score= input().split()
score = int(score)
students.append((name, student_id, score))
students.sort(key=lambda x: x[2], reverse=True)
print(students[0][0], students[0][1])
print(students[-1][0], students[-1][1])
1005 继续(3n+1)猜想
n = int(input())
numbers = list(map(int, input().split()))
res = []
for num in numbers:
while num!=1:
if num%2==0:
num=num/2
else:
num=(3*num+1)/2
if num not in res:
res.append(int(num))
key=[]
for num in numbers:
if num not in res:
key.append(num)
key.sort(reverse=True)
print(" ".join(map(str, key)))

浙公网安备 33010602011771号