1、这里统计完了之后需要以字母顺序输出
import sys data = sys.stdin.readline().strip() ans = {} for i in data: if i not in ans: ans[i]=1 else: ans[i]+=1 k = sorted(ans) res ='' for i in k: res = res+str(i)+'='+str(ans[i])+' ' print(res[:-1])2、
import sys data = sys.stdin.readline().strip() list_58 = [5,6,7,8] max = 0 res ='' for i,v in enumerate(data): num = int(v) l = '' if num in list_58: temp = i count = 1 l = l+v # print(data[temp]) while True: temp = temp+1 if temp<len(data): if int(data[temp]) in list_58: count+=1 l = l+data[temp] # print(data[temp]) else: break else: break # print() if count>max: max = count res = l print(res)3、这个笔试的时候只过了75%,输入数据没有处理好,没有考虑到[ ]和[10]这两种情况,造成了数组溢出,重新修改了下,不保证100%正确,欢迎大家指出优化点!!
import sys money = sys.stdin.readline().strip() money = money[1:-1] money = money.split(',') total = 0 for i,v in enumerate(money): if v == '': continue money[i] = int(v) if 0<len(money)<=5: while money: t = money.pop() if type(t) == type(1): total += t else: i = 0 j = 5 while j>=0: temp = 0 if i == 0: money_list = money[i:j] else: money_list = money[0:j] + money[len(money)+i:] i-=1 j-=1 for k in money_list: temp += k if temp>total: total = temp print(total)
全部评论
(1) 回帖