![](https://img-blog.csdnimg.cn/20210625222752315.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
PAT乙级考试(Python)
浙江大学计算机程序设计能力考试(Programming Ability Test,简称PAT)是由浙江大学计算机科学与技术学院组织的统一考试。旨在培养和展现学生分析问题、解决问题和计算机程序设计的能力,科学评价计算机程序设计人才,并为企业选拔人才提供参考标准。
敲代码的小风
是书何以作?曰:为以夷攻夷而作,为以夷款夷而作,为师夷长技以制夷而作。
展开
-
PAT2021-12-19乙级
test1.pyN,W = list(map(eval,input().split()))# print(N,type(N),W,type(W))weights = list(map(eval,input().split()))# print(weights,type(weights))melonNum, boxNum = 0, 0currentWeight, currentMelon = 0, 0for i in range(N): if currentWeight+weights原创 2021-12-19 21:05:19 · 322 阅读 · 0 评论 -
PAT 乙级(Python) #1094 谷歌的招聘 (20 分)
#1094 谷歌的招聘 (20 分)代码展示:L, K = list(map(eval,input().split()))N = input()find = 404def is_prime(num): if num < 2: return False if num == 3 or num == 2: return True for i in range(2,int(pow(num,0.5))+1): if num原创 2021-07-28 09:20:21 · 377 阅读 · 0 评论 -
PAT 乙级(Python) #1093 字符串A+B (20 分)
#1093 字符串A+B (20 分)代码展示:A = input()B = input()result = ""char_set = set()for char in A: if char in char_set: continue else: result += char char_set.add(char)for char in B: if char in char_set: continue原创 2021-07-28 09:20:05 · 126 阅读 · 0 评论 -
PAT 乙级(Python) #1092 最好吃的月饼 (20 分)
#1092 最好吃的月饼 (20 分)代码展示:N, M = list(map(eval,input().split()))# 月饼种类数, 城市数量scores = [0] * Nfor i in range(M): temp_scores = list(map(eval,input().split())) for j in range(N): scores[j] += temp_scores[j]scores = [0] + scoreshighest原创 2021-07-28 09:19:34 · 195 阅读 · 0 评论 -
PAT 乙级(Python) #1091 N-自守数 (15 分)
#1091 N-自守数 (15 分)代码展示:M = eval(input())data = input().split()def check(num): num_str = num num_int = int(num) for i in range(1,10): if str(i*(num_int**2)).endswith(num_str): print(i, i*(num_int**2)) return原创 2021-07-28 09:19:15 · 214 阅读 · 0 评论 -
PAT 乙级(Python) #1090 危险品装箱 (25 分)
#1090 危险品装箱 (25 分)代码展示:# 不相容物品对数, 货物清单的数量N, M = list(map(eval,input().split()))incompatibleDic = dict()# 获得各个物品的不相容物品清单for i in range(N): a, b = list(input().split()) incompatibleDic[a] = incompatibleDic.get(a,set())|{b} incompatibleDic[原创 2021-07-28 09:19:02 · 163 阅读 · 0 评论 -
PAT 乙级(Python) #1088 三人行 (20 分)
#1088 三人行 (20 分)代码展示:M, X, Y = list(map(int,input().split()))bing = Nonefor jia in range(99,9,-1): # print(jia) yi = int(str(jia)[::-1]) if abs(jia-yi)==X*int(yi/Y) and yi%Y==0: bing=yi//Y break def getInfo(data): if d原创 2021-07-28 09:18:43 · 232 阅读 · 0 评论 -
PAT 乙级(Python) #1087 有多少不同的值 (20 分)
#1087 有多少不同的值 (20 分)代码展示:N = int(input())count = 0flag = -1for i in range(1,N+1): # sum = (i//2) + (1//3) + (i//5) sum = (int(i/2) + int(1/3) + int(i/5)) if flag != sum: count += 1 flag = sumprint(count)测评结果:...原创 2021-07-28 09:18:28 · 123 阅读 · 0 评论 -
PAT 乙级(Python) #1086 就不告诉你 (15 分)
#1086 就不告诉你 (15 分)代码展示:a, b = list(map(eval,input().split()))sum = str(a * b)sum = sum[::-1].lstrip('0')print(sum)测评结果:原创 2021-07-27 12:25:07 · 259 阅读 · 0 评论 -
PAT 乙级(Python) #1085 PAT单位排行 (25 分)
#1085 PAT单位排行 (25 分)代码展示:N = eval(input())rankDict = {}for i in range(N): id, score, school = input().split() score = int(score) school = school.lower() if id[0]=='B': score = (score/1.5) elif id[0]=='A': pass原创 2021-07-27 12:24:41 · 222 阅读 · 0 评论 -
PAT 乙级(Python) #1082 射击比赛 (20 分)
#1082 射击比赛 (20 分)代码展示:N = eval(input())info = []for i in range(N): data = input().split() info.append(data)info.sort(key=lambda x:(int(x[1]))**2+(int(x[2]))**2)champion = info[0]loser = info[-1]print(champion[0],loser[0])测评结果:...原创 2021-07-27 12:24:28 · 299 阅读 · 0 评论 -
PAT 乙级(Python) #1081 检查密码 (15 分)
#1081 检查密码 (15 分)代码展示:N = eval(input())def check(password): if test_case1(password): return elif test_case2(password): return elif test_case3(password): return else: print('Your password is wan mei.')原创 2021-07-27 12:24:15 · 214 阅读 · 0 评论 -
PAT 乙级(Python) #1078 字符串压缩与解压 (20 分)
#1078 字符串压缩与解压 (20 分)代码展示:# 1078 字符串压缩与解压 (20 分)def codeStrint(info): # 'TTTTThhiiiis isssss a tesssst CAaaa as' => '5T2h4is i5s a3 te4st CA3a as' cnt = '' char = '' for c in info: if c != char: if cnt == 1:原创 2021-07-27 12:24:01 · 338 阅读 · 0 评论 -
PAT 乙级(Python) #1077 互评成绩计算 (20 分)
#1077 互评成绩计算 (20 分)代码展示:N, M = list(map(eval,input().split()))result = list()for i in range(N): grades = list(map(eval,input().split())) teacher = grades[0] legalGrade = [] for g in grades[1:]: if 0 <= g <= M:原创 2021-07-27 12:23:43 · 215 阅读 · 0 评论 -
PAT 乙级(Python) #1072 开学寄语 (20 分)
#1072 开学寄语 (20 分)代码展示:N, M = list(map(eval,input().split()))forfeit = input().split()count_stu, count_for = 0, 0def check(info): global count_stu, count_for name = info[0] temp = [name+':'] for item in info[2:]: if item in fo原创 2021-07-27 12:23:30 · 224 阅读 · 0 评论 -
PAT 乙级(Python) #1067 试密码 (20 分)
#1067 试密码 (20 分)代码展示:truth, N = input().split()N = int(N)while N>0: password = input() if password == '#': break elif password != truth: print('Wrong password:',password) N -= 1 elif password == truth:原创 2021-07-27 12:22:44 · 174 阅读 · 0 评论 -
PAT 乙级(Python) #1065 单身狗 (25 分)
#1065 单身狗 (25 分)代码展示:N = eval(input()) # num of couplescoupleLis = list()for i in range(N): a, b = input().split() coupleLis.append((a,b))M = eval(input())ls = input().split()personSet = set(ls) for a,b in coupleLis: if a in per原创 2021-07-27 12:22:30 · 351 阅读 · 0 评论 -
PAT 乙级(Python) #1071 小赌怡情 (15 分)
#1071 小赌怡情 (15 分)代码展示:Token, K = list(map(int,input().split()))for i in range(K): n1, b, t, n2 = list(map(int,input().split())) if t > Token: print('Not enough tokens. Total = {}.'.format(Token)) continue elif Token<原创 2021-07-27 12:23:06 · 218 阅读 · 0 评论 -
PAT 乙级(Python) #1064 朋友数 (20 分)
#1064 朋友数 (20 分)代码展示:N = eval(input())numbers = list(map(eval,(input().split())))def getFriendsNum(num): num = str(num) count = 0 for char in num: count += int(char) return countdic = {}for num in numbers: Friendnum = ge原创 2021-07-26 11:52:12 · 194 阅读 · 0 评论 -
PAT 乙级(Python) #1063 计算谱半径 (20 分)
#1063 计算谱半径 (20 分)代码展示:N = eval(input()) maxMagnitude = -1for i in range(N): a, b = list(map(eval,input().split())) maxMagnitude = a*a + b*b if a*a + b*b >= maxMagnitude else maxMagnitude print('{0:<.2f}'.format(maxMagnitude**0.5)原创 2021-07-26 11:51:57 · 244 阅读 · 0 评论 -
PAT 乙级(Python) #1060 爱丁顿数 (25 分)
#1060 爱丁顿数 (25 分)代码展示:N = eval(input())miles = list(map(eval,(input().split())))E = int(min(N,max(miles)))while True: temp = [item for item in miles if item>=E] if len(temp) >= E: break else: E -= 1print(E)测评结果:原创 2021-07-26 11:51:35 · 193 阅读 · 0 评论 -
PAT 乙级(Python) #1057 数零壹 (20 分)
#1057 数零壹 (20 分)代码展示:txt = input().lower()# txt = 'PAT (Basic)'.lower()total = 0find = Falsefor char in txt: if 'a'<=char<='z': total += ord(char) - ord('a') + 1 find = True# print(total)binary_char = bin(total)[2:]# pri原创 2021-07-26 11:51:18 · 222 阅读 · 0 评论 -
PAT 乙级(Python) #1054 求平均值 (20 分)
#1054 求平均值 (20 分)代码展示:N = eval(input())data = input().split()# print('N =',N)# print("data =",data)K = 0Y = 0for item in data: try: value = eval(item) except: print('ERROR: {} is not a legal number'.format(item)) c原创 2021-07-26 11:50:59 · 193 阅读 · 0 评论 -
PAT 乙级(Python) #1051 复数乘法 (15 分)
#1051 复数乘法 (15 分)代码展示:from math import sin,cosR1, P1, R2, P2 = list(map(eval,input().split())) # R1, P1, R2, P2 = 2.3, 3.5, 5.2, 0.4c1 = R1 * complex(cos(P1),sin(P1))c2 = R2 * complex(cos(P2),sin(P2))res = c1*c2# print(res.real,res.imag)if res.i原创 2021-07-26 11:50:42 · 177 阅读 · 0 评论 -
PAT 乙级(Python) #1047 编程团体赛 (20 分)
#1047 编程团体赛 (20 分)代码展示:N = eval(input())grades = [-1]*1002for i in range(N): info = input().split() ID = int(info[0].split('-')[0]) if grades[ID] == -1: grades[ID] = 0 score = int(info[1]) grades[ID] += scorebestScore = ma原创 2021-07-26 11:50:28 · 190 阅读 · 0 评论 -
PAT 乙级(Python) #1046 划拳 (15 分)
#1046 划拳 (15 分)代码展示:N = eval(input())count_jia = 0count_yi = 0for i in range(N): jiaHan, jiaHua, yiHan, yiHua = list(map(eval,(input().split()))) truth = jiaHan + yiHan if truth == jiaHua and truth != yiHua: count_yi += 1 elif原创 2021-07-26 11:50:14 · 131 阅读 · 0 评论 -
PAT 乙级(Python) #1043 输出PATest (20 分)
#1043 输出PATest (20 分)代码展示:txt = input()count_P = txt.count('P')count_A = txt.count('A')count_T = txt.count('T')count_e = txt.count('e')count_s = txt.count('s')count_t = txt.count('t')# PATestPATest....count = count_P + count_A + count_T + coun原创 2021-07-26 11:49:58 · 199 阅读 · 0 评论 -
PAT 乙级(Python) #1042 字符统计 (20 分)
#1042 字符统计 (20 分)代码展示:text = input().lower()# print(text)statDict = dict()for char in text: if 'a'<=char<="z": statDict[char] = statDict.get(char,0) + 1statLis = list(statDict.items())# print('statLis =',statLis)statLis.sort(ke原创 2021-07-26 11:49:43 · 211 阅读 · 0 评论 -
PAT 乙级(Python) #1041 考试座位号 (15 分)
#1041 考试座位号 (15 分)代码展示:N = eval(input()) # 考生数量info = dict() for i in range(N): id, test, exam = input().split() info[test] = [id,exam]M = eval(input())testNums = input().split()for item in testNums: print(info[item][0],info[item][1])原创 2021-07-28 09:20:33 · 225 阅读 · 0 评论 -
PAT 乙级(Python) #1040 有几个PAT (25 分)
#1040 有几个PAT (25 分)代码展示:chars = input()count = 0countP = chars.count("P")countT = chars.count("T")"PAT"tempP = 0tempT = countTfor char in chars: if char == 'A': count += (tempP*tempT) elif char == 'P': tempP += 1 elif原创 2021-07-25 00:24:05 · 237 阅读 · 0 评论 -
PAT 乙级(Python) #1039 到底买不买 (20 分)
#1039 到底买不买 (20 分)代码展示:vendor = input()target = input()pearlDict = {}for c in vendor: pearlDict[c] = pearlDict.get(c,0) + 1flag = 'Yes'for c in target: pearlDict[c] = pearlDict.get(c,0) - 1 if pearlDict[c] < 0: flag = 'No'if原创 2021-07-25 00:23:46 · 193 阅读 · 0 评论 -
PAT 乙级(Python) #1038 统计同成绩学生 (20 分)
#1038 统计同成绩学生 (20 分)代码展示:N = eval(input())grades = list(map(eval,(input().split())))search = list(map(eval,(input().split())))[1:]result = []for item in search: result.append(grades.count(item))print(*result,sep=' ')测评结果:...原创 2021-07-25 00:23:31 · 201 阅读 · 0 评论 -
PAT 乙级(Python) #1036 跟奥巴马一起编程 (15 分)
#1036 跟奥巴马一起编程 (15 分)代码展示:N, sign = input().split()N = int(N)print(sign*N)line = sign + (' '*(N-2)) + signfor i in range((N+1)//2-2): print(line)print(sign*N)测评结果:原创 2021-07-25 00:23:14 · 189 阅读 · 0 评论 -
PAT 乙级(Python) #1032 挖掘机技术哪家强 (20 分)
#1032 挖掘机技术哪家强 (20 分)代码展示:N = int(input())info = [-1 for i in range(100010)]for i in range(N): id, grade = list(map(eval,input().split())) if info[id] == -1: info[id] = 0 info[id] += grademax_grade = max(info)max_id = info.index原创 2021-07-25 00:23:00 · 335 阅读 · 0 评论 -
PAT 乙级(Python) #1031 查验身份证 (15 分)
#1031 查验身份证 (15 分)代码展示:N = eval(input())def check(ID): '''检查身份证号是否合法''' if not (ID[:-1]).isdecimal(): return False elif str(getCheckSum(ID[:-1])) == ID[-1]: return True else: return Falsedef getCheckSum(number原创 2021-07-25 00:22:40 · 280 阅读 · 0 评论 -
PAT 乙级(Python) #1027 打印沙漏 (20 分)
#1027 打印沙漏 (20 分)代码展示:K, sign = input().split()K = eval(K)depth = int(pow((K+1)/2,0.5))residual = K - (2*depth*depth-1)delta = -2num_sign = depth * 2 - 1for i in range(2*depth-1): num_space = ((depth * 2 - 1) - num_sign)//2 info = (" "*nu原创 2021-07-25 00:22:26 · 295 阅读 · 0 评论 -
PAT 乙级(Python) #1026 程序运行时间 (15 分)
#1026 程序运行时间 (15 分)代码展示:c1, c2 = list(map(eval,(input().split())))# c1, c2 = 123, 4577973CLK_TCK = 100delta = (c2 - c1) / CLK_TCKhh = int(delta/3600)mm = int((delta - hh*3600) / 60)ss = delta - hh*3600 - mm*60# ss=round(ss)if ss - int(ss) >=原创 2021-07-25 00:22:08 · 201 阅读 · 0 评论 -
PAT 乙级(Python) #1025 反转链表 (25 分)
#1025 反转链表 (25 分)代码展示:headerAddress, N, K = input().split()N, K = int(N), int(K)# 映射类型 -> 'address':['data','next','pre']NodeDict = dict()for i in range(N): address, data, next = input().split() NodeDict[address] = [data, next]# 遍历链表添加前原创 2021-07-25 00:21:46 · 343 阅读 · 0 评论 -
PAT 乙级(Python) #1023 组个最小数 (20 分)
#1023 组个最小数 (20 分)代码展示:data = list(map(eval,(input().split())))digits = []for i in range(10): digits += ([i]*data[i])# print(digits)zeros = digits[0:data[0]]nonzeros = digits[data[0]:]result = [nonzeros[0]]result += zerosresult += (nonzeros[原创 2021-07-25 00:21:10 · 111 阅读 · 0 评论 -
PAT 乙级(Python) #1022 D进制的A+B (20 分)
#1022 D进制的A+B (20 分)代码展示:A, B, D = list(map(eval,(input().split())))sumAB = A + B result = []while sumAB!=0: temp = sumAB % D sumAB = sumAB // D result.append(str(temp))if len(result)!=0: print(''.join(result[::-1]))else: print(原创 2021-07-24 22:37:00 · 108 阅读 · 3 评论