360菜鸡笔试求解答
1.合法问卷问题,卡在45%。。。我不明白
2.数组操作,1是交换最后一个和最前一个,2是两两交换,超时,我自闭了/。。。
题1
# 输入第一行包含一个正整数n,表示收到的问卷数量。(1<=n<=2000) #如果名字仅由大小写英文字母组成且长度不超过10 # 接下来有n行,每行有一个由大小写英文字母,数字,下划线组成的字符串, #分别表示一份问卷的名字,字符串长度不超过100。 import re regex = re.compile(r'[a-zA-Z]+') num = int(input().strip()) result = 0 for i in range(num): s = input() if s and len(s)<=10 and re.match(regex,s).group()==s: result += 1 print(result)题2
def process1(a):
new = a.pop(0)
a.append(new)
return a
def process2(a):
for i in range(0,len(a),2):
a[i],a[i+1]=a[i+1],a[i]
return a
N,M = (input().split())
a = [str(i) for i in range(1,int(N)+1)]
process = input().split()
for i in range(int(M)):
if process[i]=='1':
a = process1(a)
else:
a = process2(a)
print(' '.join(a))
查看23道真题和解析