360笔试,赛码崩了
360
第一题 ,合法名字,ac
n = int(input()) count = 0 for i in range(n): name = input() # 长度判断 leng = len(name) if leng > 10: continue count += 1 for key in name: if 'a' <= key <= 'z'&nbs***bsp;'A' <= key <= 'Z': continue else: count -= 1 break print(count)第二题 n个数字m次操作,第一次ac0.45,超时,下面是优化后的代码,本地测试没问题,复制到网站,网站就崩了,欲哭无泪。
nums = list(map(int,input().split())) n,m = nums[0],nums[1] m_nums = list(map(int,input().split())) list1 = [i for i in range(1,n+1)] i = 0 while i<m: if i<m and m_nums[i]==1: while i<m and m_nums[i]!=2 : i+=1 print(i) list1 = list1[i:]+list1[:i] if i<m and m_nums[i]==2: pre = i while i<m and m_nums[i]!=1 : i+=1 if (i-pre)%2==0: continue else: k = 0 while k <= len(list1) - 2: list1[k], list1[k + 1] = list1[k + 1], list1[k] k += 2 for num in list1: print(num,end=' ')