哪里网站开发小程序,mvc在网站开发中的应用,凡科建站的建站后如何管理,宣传册排版设计与制作输入样例#xff1a;
10 C J J B C B B B B C C C C B J B B C J J 输出样例#xff1a;
5 3 2 2 3 5 B B
本题有几个地方需要注意#xff1a;
当甲乙没有赢#xff0c;怎么输出#xff0c;正确答案是都输出B#xff0c;这个在题目中找不出线索#xff0c;有点坑
10 C J J B C B B B B C C C C B J B B C J J 输出样例
5 3 2 2 3 5 B B
本题有几个地方需要注意
当甲乙没有赢怎么输出正确答案是都输出B这个在题目中找不出线索有点坑使用python超时优化考虑的有三点1⃣️使用sys.stdin作为输入尤其是在大量输入数据时2⃣️以空间换时间使用一维或者多维list建立索引3⃣️将执行代码放到函数中至于为什么这样可以提高效率主要基于cpython的机制问题大概是因为局部变量和全局变量存取效率不一样pta中python超市一般出现在用for循环输入大量数据时可以考虑上面的优化策略pta这种在线题目的三板斧是1⃣️把题目需要的输入输出准确信息准确提炼映射到合适的数据结构2⃣️保证样例正确把主流逻辑调通3⃣️自己设计一些和0、1相关的边界数据把边界条件调通什么数组越界、函参不匹配大概都在这一步4⃣️提交测试根据返回信息再次调试如果是错误问题那就需要检查主逻辑和边界条件如果超时就使用上面的优化策略。
# -*- coding: utf-8 -*-
from collections import defaultdict
import sysstat {C B: -1,C J: 1,B C: 1,B J: -1,J C: -1,J B: 1,C C: 0,B B: 0,J J: 0}def comp(x):return str(x[1]) str(ord(z) - ord(x[0]))if __name__ __main__:result defaultdict(int)win_stat_0 defaultdict(int)win_stat_1 defaultdict(int)n eval(sys.stdin.readline().strip())for i in range(n):input_str sys.stdin.readline().strip()result[stat[input_str]] 1if stat[input_str] 1:win_stat_0[input_str[0]] 1elif stat[input_str] -1:win_stat_1[input_str[2]] 1print(result[1], result[0], result[-1])print(result[-1], result[0], result[1])if len(win_stat_0) 0:print(sorted(win_stat_0.items(), keycomp, reverseTrue)[0][0], end)else:print(B, end)print( , end)if len(win_stat_1) 0:print(sorted(win_stat_1.items(), keycomp, reverseTrue)[0][0])else:print(B)