PTA-乙

1001 害死人不偿命的(3n+1)猜想

原题链接

1
2
3
4
5
6
7
8
9
n = int(input())
cnt = 0
while n != 1:
if n % 2 == 0:
n = n / 2
else:
n = (3 * n + 1) / 2
cnt += 1
print(cnt)

1002 写出这个数

原题链接

1
2
3
4
5
6
inp = input()
d = ['ling', 'yi', 'er', 'san', 'si', 'wu', 'liu', 'qi', 'ba', 'jiu']
l = [int(x) for x in inp]
s = str(sum(l))
l = [d[int(x)] for x in s]
print(' '.join(l))

1004 成绩排名

原题链接

1
2
3
4
5
6
7
8
9
10
11
12
n = int(input())
students = []
for _ in range(n):
student = {}
line = input().split(' ')
student['name'] = line[0]
student['id'] = line[1]
student['score'] = int(line[2])
students.append(student)
students.sort(key=lambda x:x['score'], reverse=True)
print("{} {}".format(students[0]['name'], students[0]['id']))
print("{} {}".format(students[n - 1]['name'], students[n - 1]['id']))

1009 说反话

原题链接

1
2
s = input().split(' ')
print(' '.join(s[::-1]))

1021 个位数统计

原题链接

1
2
3
4
5
6
7
8
9
10
11
s = input()
l = [int(x) for x in s]
count = {}
for x in l:
if x not in count:
count[x] = 1
else:
count[x] += 1
for i in range(10):
if i in count:
print("{}:{}".format(i, count[i]))

1022 D进制的A+B

原题链接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
inp = input().split(' ')
a = int(inp[0])
b = int(inp[1])
d = int(inp[2])

c = a + b
l = []
while c > 0:
l.append(str(c % d))
c = c // d
l.reverse()
n = len(l)
i = 0
while i < n and l[i] == '0':
i += 1
pr = ''.join(l[i:])
if pr is None or pr == '':
print(0)
else:
print(pr)

1031 查验身份证

原题链接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
passed = 0
w = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
mpt = {'0':'1', '1':'0', '2':'X', '3':'9', '4':'8', '5':'7', '6':'6', '7':'5', '8':'4', '9':'3', '10':'2'}
def f(a):
s = 0
for i in range(17):
s += w[i] * a[i]
return mpt[str(s % 11)]
n = int(input())
for _ in range(n):
idx = input()
l = []
isletter = False
for x in idx[:-1]:
if x >= '0' and x <= '9':
l.append(int(x))
else:
isletter = True
break
if isletter or len(idx) < 18:
print("{}".format(idx))
else:
z = f(l)
if idx[-1] == z:
passed += 1
else:
print("{}".format(idx))
if passed == n:
print("All passed")

1032 挖掘机技术哪家强

原题链接

这题用Python会超时,用C语言没问题。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>

const int N = 1e5 + 10;
int a[N];

int main() {
int n;
scanf("%d", &n);
int max_id = -1, max_sc = -1;
for (int i = 0; i < n; ++ i){
int id, sc;
scanf("%d%d", &id, &sc);
a[id] += sc;
if (max_id == -1 || max_sc < a[id]) {
max_id = id;
max_sc = a[id];
}
}
printf("%d %d\n", max_id, max_sc);
return 0;
}

1033 旧键盘打字

原题链接

1
2
3
4
5
6
7
8
9
10
11
12
13
ban = input()
s = input()
upper = [chr(i) for i in range(ord('A'), ord('Z')+1)]
broke = {}
for x in ban:
if x == '+':
for u in upper:
broke[u] = 1
else:
if x >= 'A' and x <= 'Z':
broke[chr(ord(x) - ord('A') + ord('a'))] = 1
broke[x] = 1
print("".join([x if x not in broke else '' for x in s]))

1036 跟奥巴马一起编程

原题链接

1
2
3
4
5
6
7
8
import math
line = input().split(' ')
n, ch = int(line[0]), line[1]
width, heigh = n, int(math.ceil(n / 2))
print(ch * width)
for _ in range(heigh - 2):
print(ch + ' ' * (width - 2) + ch)
print(ch * width)

1038 统计同成绩学生

原题链接

1
2
3
4
5
6
7
8
9
10
n = int(input())
sts = input().split(' ')
sts = [int(x) for x in sts]
scs = [0] * 101
for s in sts:
scs[s] += 1
query = input().split(' ')
query = [int(x) for x in query]
res = [str(scs[x]) for x in query[1:]]
print(" ".join(res))

1041 考试座位号

原题链接

1
2
3
4
5
6
7
8
9
n = int(input())
sts = {}
for _ in range(n):
line = input().split(' ')
sts[line[1]] = {'id': line[0], 'se': line[2]}
m = int(input())
query = input().split(' ')
for q in query:
print("{} {}".format(sts[q]['id'], sts[q]['se']))

1042 字符统计

原题链接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
line = input()
cnt = {}
line = line.lower()
for x in line:
if x not in cnt:
cnt[x] = 1
else:
cnt[x] += 1
maxn, maxn_chr = 0, None
for x in range(26):
ch = chr(ord('a') + x)
if ch not in cnt:
continue
if maxn_chr is None or maxn < cnt[ch]:
maxn_chr = ch
maxn = cnt[ch]
print(f"{maxn_chr} {maxn}")

1047 编程团体赛

原题链接

1
2
3
4
5
6
7
8
9
10
11
n = int(input())
teams = [0] * 1010
max_team, max_sc = None, None
for _ in range(n):
line = input().split(' ')
team, _ = line[0].split('-')
team = int(team)
teams[team] += int(line[1])
if max_team is None or max_sc < teams[team]:
max_team, max_sc = team, teams[team]
print(f"{max_team} {max_sc}")

1056 组合数的和

原题链接

找规律:n个数字,每个数字在十位和各位都会出现n -1次。

Sum = 11 * num * (n-1)

1
2
3
4
5
6
7
line = input().split(' ')
line = [int(x) for x in line]
n, arr = line[0], line[1:]
res = 0
for x in arr:
res += 11 * x * (n - 1)
print(res)

未完待续


PTA-乙
https://liaoweiquan.github.io/2021/07/31/PTA-乙/
作者
泉泉
发布于
2021年7月31日
许可协议