快手笔试
第一题:AC 50%
import sys """ 规律:A(N) = A(N-1) 将n与对应的字母相对应:chr(n + 64) """ if __name__ == "__main__": def helper(n): if n == 1: return 'A' else: return helper(n - 1) + chr(n + 64) + helper(n - 1) n = int(sys.stdin.readline().strip()) # 非法情况 if n <= 0 and n > 26: print("input error") # 正常情况 else: print(helper(n))
import sys if __name__ == "__main__": def printStr(line): res = [] for s in line: # 当前字符不是数字 if s not in hp: res.append(s) else: tmp = (int(s) - 1) * res[-1] res.append(tmp) print("".join(res)) hp = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} # 'b3c2a' line = sys.stdin.readline().strip() # 空字符串或第一位为数字 if not line&nbs***bsp;line[0] in hp: print("") else: printStr(line)
第三题: AC 72%
import sys if __name__ == "__main__": def printIndex(array): n = len(array) res = [] for i in range(n): count = 0 for j in range(0, i): if array[j] > array[i]: count += 1 # 没必要再循环下去 if count > 1: break # 查看count值 if count == 1: res.append(i) for index in res: print(index, end=" ") # '1 22 22 33 22 12 45 44 5' line = sys.stdin.readline().strip() # [1, 22, 22, 33, 22, 12, 45, 44, 5] values = list(map(int, line.split())) # 空 if not values: print(-1) # 非空 else: printIndex(values)