PAT乙级题:python 1076 Wifi密码 (15分)

it2023-03-18  86

下面是微博上流传的一张照片:“各位亲爱的同学们,鉴于大家有时需要使用 wifi,又怕耽误亲们的学习,现将 wifi 密码设置为下列数学题答案:A-1;B-2;C-3;D-4;请同学们自己作答,每两日一换。谢谢合作!!~”—— 老师们为了促进学生学习也是拼了…… 本题就要求你写程序把一系列题目的答案按照卷子上给出的对应关系翻译成 wifi 的密码。这里简单假设每道选择题都有 4 个选项,有且只有 1 个正确答案。

输入格式:

输入第一行给出一个正整数 N(≤ 100),随后 N 行,每行按照 编号-答案 的格式给出一道题的 4 个选项,T 表示正确选项,F 表示错误选项。选项间用空格分隔。

输出格式:

在一行中输出 wifi 密码。

输入样例

8 A-T B-F C-F D-F C-T B-F A-F D-F A-F D-F C-F B-T B-T A-F C-F D-F B-F D-T A-F C-F A-T C-F B-F D-F D-T B-F C-F A-F C-T A-F B-F D-F

输出样例:

13224143

代码: 我做的方法有点点笨,需要注意的是因为每行输入的顺序是打乱的,所以不能只判断4次,而是应该判断16次。

N = int(input()) #第一行所给出的正整数 a = 'A-T' b = 'B-T' c = 'C-T' d = 'D-T' code = [] #列表每个元素即密码 for i in range(N): ipa,ipb,ipc,ipd = input().split(' ') #ip是一个中间变量 #如果这样写 乱序就没有办法弄了 if ipa == a: code.append(1) if ipa == b: code.append(2) if ipa == c: code.append(3) if ipa == d: code.append(4) if ipb == a: code.append(1) if ipb == b: code.append(2) if ipb == c: code.append(3) if ipb == d: code.append(4) if ipc == a: code.append(1) if ipc == b: code.append(2) if ipc == c: code.append(3) if ipc == d: code.append(4) if ipd == a: code.append(1) if ipd == b: code.append(2) if ipd == c: code.append(3) if ipd == d: code.append(4) for j in range(N): print(code[j],end = '')

最新回复(0)