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

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

1002 写出这个数

1
2
3
4
5
6
7
8
9
n = input()
res = 0
for char in n:
res += int(char)
dicts = ['ling', 'yi', 'er', 'san', 'si', 'wu', 'liu', 'qi', 'ba', 'jiu']
ans = []
for char in str(res):
ans.append(dicts[int(char)])
print(' '.join(map(str, ans)))

1003 我要通过!

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
n = int(input())
def check(arg):
length = len(arg)
idx = cnt1 = cnt2 = cnt3 = 0
while idx < length and arg[idx] == 'A':
cnt1 += 1
idx += 1
if idx < length and arg[idx] == 'P':
idx += 1
else:
return False
while idx < length and arg[idx] == 'A':
idx += 1
cnt2 += 1
if idx < length and arg[idx] == 'T':
idx += 1
else:
return False
while idx < length and arg[idx] == 'A':
idx += 1
cnt3 += 1
if idx == length and cnt1 * cnt2 == cnt3 and cnt2:
return True
else:
return False
for _ in range(n):
a = input()
print('YES' if check(a) else 'NO')

1004 成绩排名

1
2
3
4
5
6
7
8
n = int(input())
students = []
for i in range(n):
name, number, grade = input().split()
students.append([name, number, grade])
students.sort(key=lambda x: int(x[2]))
print(students[-1][0], students[-1][1])
print(students[0][0], students[0][1])

1005 继续(3n+1)猜想

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
n = int(input())
nums = list(map(int, input().split()))
res = nums[:]
def check(num):
while num != 1:
if num % 2 == 0:
num = num // 2
else:
num = (3 * num + 1) // 2
if num in res:
res.remove(num)
return
for num in nums:
check(num)
res.sort(reverse=True)
print(' '.join(map(str, res)))

1006 换个格式输出整数

1
2
3
n = '00' + input()
res = 'B' * int(n[-3]) + 'S' * int(n[-2]) + ''.join([str(i) for i in range(1, int(n[-1]) + 1)])
print(res)

1007 素数对猜想

1
2
3
4
5
6
7
8
9
10
11
12
13
n = int(input())
state = [True] * (n + 1)
primes = []
for i in range(2, n + 1):
if state[i]:
primes.append(i)
for j in range(i * 2, n + 1, i):
state[j] = False
res = 0
for i in range(len(primes) - 1):
if primes[i + 1] - primes[i] == 2:
res += 1
print(res)

1008 数组元素循环右移问题

1
2
3
4
n, m = map(int, input().split())
nums = list(map(int, input().split()))
nums = nums[n - m: ] + nums[: n - m]
print(' '.join(map(str, nums)))

1009 说反话

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

1010 一元多项式求导

1
2
3
4
5
6
7
8
9
10
nums = list(map(int, input().split()))
res = []
for i in range(0, len(nums), 2):
a = nums[i] * nums[i + 1]
b = nums[i + 1] - 1
if a:
res.extend((a, b))
if not res:
res.extend((0, 0))
print(' '.join(map(str, res)))

1011 A+B 和 C

1
2
3
4
5
6
7
t = int(input())
for i in range(1, t + 1):
a, b, c = map(int, input().split())
if a + b > c:
print(f'Case #{i}: true')
else:
print(f'Case #{i}: false')

1012 数字分类

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
nums = list(map(int, input().split()))
res1 = res2 = len2 = res3 = res4 = len4 = res5 = 0
for num in nums[1: ]:
if num % 10 == 0:
res1 += num
elif num % 5 == 1:
res2 += (-1) ** (len2 % 2) * num
len2 += 1
elif num % 5 == 2:
res3 += 1
elif num % 5 == 3:
res4 += num
len4 += 1
elif num % 5 == 4:
res5 = num if num > res5 else res5
if not res1:
res1 = 'N'
if not len2:
res2 = 'N'
if not res3:
res3 = 'N'
if len4:
res4 = round(res4 / len4, 1)
else:
res4 = 'N'
if not res5:
res5 = 'N'
print(res1, res2, res3, res4, res5)

1013 数素数

1
2
3
4
5
6
7
8
9
10
11
m, n = map(int, input().split())
state = [True] * 600000
for i in range(2, int(600000**0.5) + 1):
if state[i]:
for j in range(i * i, 600000, i):
state[j] = False
primes = [num for num in range(2, 600000) if state[num]]
tmps = primes[m - 1: n]
ress = [tmps[i:i+10] for i in range(0, len(tmps), 10)]
for res in ress:
print(' '.join(map(str, res)))

1014 福尔摩斯的约会

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
s1, s2, s3, s4 = input(), input(), input(), input()
len1, len2 = min(len(s1), len(s2)), min(len(s3), len(s4))
res = []
DAY = {'A': "MON", 'B': "TUE", 'C': "WED", 'D': "THU", 'E': "FRI", 'F': "SAT", 'G': "SUN"}
for i in range(len1):
if s1[i] == s2[i] and 'A' <= s1[i] <= 'G':
res.append(DAY[s1[i]])
break
for j in range(i + 1, len1):
if s1[j] == s2[j]:
if '0' <= s1[j] <= '9':
res.append('0' + s1[j])
break
if 'A' <= s1[j] <= 'N':
res.append(str(ord(s1[j]) - 55))
break
for i in range(len2):
if s3[i] == s4[i] and (97 <= ord(s3[i]) <= 122 or 65 <= ord(s3[i]) <= 90):
if i < 10:
res.append('0' + str(i))
else:
res.append(str(i))
print(f'{res[0]} {res[1]}:{res[2]}')

1015 德才论(部分通过)

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
from sys import stdin
input = lambda: stdin.readline().strip()
n, l, h = map(int, input().split())
res1, res2, res3, res4 = [], [], [], []
for _ in range(n):
a, b, c = map(int, input().split())
if b >= h and c >= h:
res1.append([a, b, c, b + c])
elif b >= h and c >= l:
res2.append([a, b, c, b + c])
elif b >= l and c >= l and b >= c:
res3.append([a, b, c, b + c])
elif b >= l and c >= l:
res4.append([a, b, c, b + c])
print(len(res1) + len(res2) + len(res3) + len(res4))
res1.sort(key=lambda x: (x[3], x[1], -x[0]), reverse=True)
res2.sort(key=lambda x: (x[3], x[1], -x[0]), reverse=True)
res3.sort(key=lambda x: (x[3], x[1], -x[0]), reverse=True)
res4.sort(key=lambda x: (x[3], x[1], -x[0]), reverse=True)
for res in res1:
print(' '.join(map(str, res[: -1])))
for res in res2:
print(' '.join(map(str, res[: -1])))
for res in res3:
print(' '.join(map(str, res[: -1])))
for res in res4:
print(' '.join(map(str, res[: -1])))

1016 部分A+B

1
2
3
4
A, Da, B, Db = input().split()
Pa = Da * A.count(Da) if A.count(Da) else '0'
Pb = Db * B.count(Db) if A.count(Da) else '0'
print(int(Pa) + int(Pb))

1017 A除以B

1
2
a, b = map(int, input().split())
print(a // b, a % b)

1018 锤子剪刀布

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
31
32
n = int(input())
a = b = c = 0
jia, yi = [], []
for _ in range(n):
x, y = input().split()
jia.append(x)
yi.append(y)
if x == y:
c += 1
elif x == 'C' and y == 'J' or x == 'J' and y == 'B' or x == 'B' and y == 'C':
a += 1
jia.append(x)
else:
b += 1
yi.append(y)
print(a, c, b)
print(n - a - c, c, n - b - c)
b1, c1, j1 = jia.count('B'), jia.count('C'), jia.count('J')
b2, c2, j2 = yi.count('B'), yi.count('C'), yi.count('J')
t1, t2 = max(b1, c1, j1), max(b2, c2, j2)
if b1 == t1:
print('B', end=' ')
elif c1 == t1:
print('C', end=' ')
else:
print('J', end=' ')
if b2 == t2:
print('B')
elif c2 == t2:
print('C')
else:
print('J')

1019 数字黑洞

1
2
3
4
5
6
7
8
9
10
11
12
13
n = input()
def fun(n):
n = map(int, list(str(n).zfill(4)))
b = list(map(str, sorted(n)))
a = b[::-1]
c = ''.join(a)
d = ''.join(b)
e = int(c) - int(d)
e = str(e).zfill(4)
print(f'{c} - {d} = {e}')
if e != '0000' and e != '6174':
fun(e)
fun(n)

020 月饼

1
2
3
4
5
6
7
8
9
10
11
12
13
N, D = map(int, input().split())
stocks = list(map(float, input().split()))
prices = list(map(float, input().split()))
profits = [price / stock for stock, price in zip(stocks, prices)]
yuebings = sorted(zip(stocks, prices, profits), key=lambda x: x[2], reverse=True)
res = 0
for stock, price, profit in yuebings:
a = min(stock, D)
res += a * profit
D -= a
if not D:
break
print(f'{res:.2f}')

1021 个位数统计

1
2
3
4
5
n = input()
nums = '0123456789'
for num in nums:
if n.count(num):
print(f'{num}:{n.count(num)}')

1022 D进制的A+B

1
2
3
4
5
6
7
8
9
10
a, b, d = map(int, input().split())
c = a + b
res = []
while c:
res.append(c % d)
c //= d
if res:
print(''.join(map(str, res[::-1])))
else:
print(0)

1023 组个最小数

1
2
3
4
5
6
7
8
9
nums = list(map(int, input().split()))
res = ''
for i in range(1, 10):
if nums[i]:
nums[i] -= 1
res = str(i)
break
nums = [str(num) * nums[num] for num in range(10) if nums[num]]
print(res + ''.join(map(str, nums)))

1024 科学计数法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
a = input()
res = []
if a[0] == '-':
res.append('-')
e = a.find('E')
exp = int(a[e+2:])
if a[e + 1] == '+':
res.append(a[1])
if exp >= e - 3:
res.append(a[3: e])
res.append('0' * (exp - e + 3))
else:
res.append(a[3: 3 + exp])
res.append('.')
res.append(a[3 + exp: e])
elif a[e + 1] == '-':
res.append('0.')
if exp > 1:
res.append('0' * (exp - 1))
res.append(a[1])
res.append(a[3: e])
print(''.join(res))

1025 反转链表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
start, n, k = map(int, input().split())
datas, nexts, lst = [0] * 100001, [0] * 100001, []
for _ in range(n):
a, b, c = map(int, input().split())
datas[a], nexts[a] = b, c
while start != -1:
lst.append(start)
start = nexts[start]
cnt = len(lst)
for i in range(0, cnt - cnt % k, k):
lst[i: i + k] = lst[i: i + k][::-1]
for i in range(cnt - 1):
print(f'{lst[i]:05d} {datas[lst[i]]} {lst[i + 1]:05d}')
print(f'{lst[-1]:05d} {datas[lst[-1]]} -1')

1026 程序运行时间

1
2
3
4
5
6
7
8
9
10
11
12
c1, c2 = map(int, input().split())
t = (c2 - c1 + 50) // 100
res = []
while t:
if t % 60 < 10:
res.append('0' + str(t % 60))
else:
res.append(str(t % 60))
t //= 60
while len(res) < 3:
res.append('00')
print(':'.join( res[::-1]))

1027 打印沙漏

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
n, symbol = input().split()
shalous = []
shalou = -1
for i in range(30):
shalou += 2 * (2 * i + 1)
shalous.append(shalou)
for i in range(30):
if int(n) < shalous[i]:
break
a = 2 * (i - 1) + 1
for j in range(a, 1, -2):
print(' ' * ((a - j) // 2) + symbol * j)
for j in range(1, a + 1, 2):
print(' ' * ((a - j) // 2) + symbol * j)
print(int(n) - shalous[i - 1])

1028 人口普查(部分通过)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
from sys import stdin
input = lambda: stdin.readline().strip()
n = int(input())
nums = []
for _ in range(n):
name, birth = input().split()
y, m, d = birth.split('/')
if '18140906' <= y + m + d <= '20140906':
nums.append([name, int(y), int(m), int(d)])
nums.sort(key=lambda x: (x[1], x[2], x[3]))
if nums:
print(len(nums), nums[0][0], nums[-1][0])
else:
print(0)

1029 旧键盘

1
2
3
4
5
6
7
8
9
10
11
a, b = input(), input()
dicts = {}
for char in b:
dicts[char] = 1
res = []
for char in a:
if not dicts.get(char, 0):
if char.isalpha():
char = char.upper()
res.append(char)
print(''.join({}.fromkeys(res).keys()))

1030 完美数列

1
2
3
4
5
6
7
8
9
n, p = map(int, input().split())
nums = list(map(int, input().split()))
nums.sort()
res, j = 1, 0
for i in range(n):
while j < n and nums[j] <= nums[i] * p:
j += 1
res = max(res, j - i)
print(res)

1031 查验身份证

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
n = int(input())
dicts = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2]
weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
def check(id_card):
check_num = 0
for i in range(17):
if 48 <= ord(id_card[i]) <= 57:
check_num += int(id_card[i]) * weights[i]
else:
return False
check_num %= 11
return id_card[-1] == str(dicts[check_num])
res = 0
for _ in range(n):
id_card = input()
if not check(id_card):
print(id_card)
res += 1
if not res:
print('All passed')

1032 挖掘机技术哪家强

1
2
3
4
5
6
n = int(input())
nums = [-1] + [0] * 100000
for _ in range(n):
a, b = map(int, input().split())
nums[a] += b
print(nums.index(max(nums)), max(nums))

1033 旧键盘打字

1
2
3
4
5
6
7
8
9
10
11
12
bad, string = list(input()), input()
shift = False
for i in bad:
if i == '+':
shift = True
if 65 <= ord(i) <= 90:
bad.append(i.lower())
for i in string:
if 65 <= ord(i) <= 90 and shift:
continue
if i not in bad:
print(i, end='')

1034 有理数四则运算

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
31
32
33
34
35
36
37
38
39
40
41
42
import math
a, b = input().split()
def simplify(a):
x, y = map(int, a.split('/'))
return str(x // math.gcd(x, y)) + '/' + str(y // math.gcd(x, y))
a, b = simplify(a), simplify(b)
def calculate(a, b):
x1, y1 = map(int, a.split('/'))
x2, y2 = map(int, b.split('/'))
t = str(x1 * y2 + x2 * y1) + '/' + str(y1 * y2)
res.append(simplify(t))
t = str(x1 * y2 - x2 * y1) + '/' + str(y1 * y2)
res.append(simplify(t))
t = str(x1 * x2) + '/' + str(y1 * y2)
res.append(simplify(t))
if not x2:
res.append('1/0')
else:
if x2 < 0:
x2, y2 = -x2, -y2
t = str(x1 * y2) + '/' + str(y1 * x2)
res.append(simplify(t))
res = []
calculate(a, b)
def simplify2(a):
x, y = map(int, a.split('/'))
if not y:
return 'Inf'
ans = ''
t = abs(x) // y
if not x % y:
ans = str(t)
elif t:
ans = str(t) + ' ' + str(abs(x - t * y * x // abs(x))) + '/' + str(y)
else:
ans = str(abs(x)) + '/' + str(y)
return '(-' + ans + ')' if x < 0 else ans
a, b, res = simplify2(a), simplify2(b), [simplify2(i) for i in res]
print(f'{a} + {b} = {res[0]}')
print(f'{a} - {b} = {res[1]}')
print(f'{a} * {b} = {res[2]}')
print(f'{a} / {b} = {res[3]}')

1035 插入与归并

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
31
32
33
n = int(input())
start = list(map(int, input().split()))
mid = list(map(int, input().split()))
for i in range(n - 1, -1, -1):
if start[i] != mid[i]:
break
if sorted(mid[:i + 1]) == mid[:i + 1]:
print('Insertion Sort')
a = start[i + 1]
while a > start[i]:
i += 1
a = start[i + 1]
for j in range(i + 1):
if a < mid[j]:
print(' '.join(map(str, (mid[: j] + [a] + mid[j:i + 1] + mid[i+2:]))))
break
else:
print('Merge Sort')
i = 1
flag = True
while i < n and flag:
i *= 2
for j in range(i, n, i):
if sorted(mid[j-i: j]) != mid[j-i: j]:
flag = False
break
if i > j:
mid.sort()
else:
for j in range(i, n, i):
mid[j-i: j] = sorted(mid[j-i: j])
mid[j:] = sorted(mid[j:])
print(' '.join(map(str, mid)))

1036 跟奥巴马一起编程

1
2
3
4
5
6
7
n, c = input().split()
n = int(n)
row = int(n / 2 + 0.5) - 2
print(c * n)
for _ in range(row):
print(c + ' ' * (n - 2) + c)
print(c * n)

1037 在霍格沃茨找零钱

1
2
3
4
5
6
7
8
9
10
11
12
13
p, a = input().split()
g1, s1, k1 = map(int, p.split('.'))
g2, s2, k2 = map(int, a.split('.'))
t1 = (g1 * 17 + s1) * 29 + k1
t2 = (g2 * 17 + s2) * 29 + k2
t3 = abs(t2 - t1)
k3 = t3 % 29
s3 = t3 // 29 % 17
g3 = (t3 // 29 - s3) // 17
if t2 >= t1:
print(f'{g3}.{s3}.{k3}')
else:
print(f'-{g3}.{s3}.{k3}')

1038 统计同成绩学生

1
2
3
4
5
6
7
8
9
10
n = int(input())
nums = list(map(int, input().split()))
checks = list(map(int, input().split()))
scores = [0] * 101
for num in nums:
scores[num] += 1
res = []
for check in checks[1:]:
res.append(scores[check])
print(' '.join(map(str, res)))

1039 到底买不买

1
2
3
4
5
6
7
8
9
10
11
12
s, t = input(), input()
a, dict1 = 0, {}
for char in s:
dict1[char] = dict1.get(char, 0) + 1
for char in t:
if dict1.get(char, 0):
a += 1
dict1[char] -= 1
if a == len(t):
print(f'Yes {len(s) - len(t)}')
else:
print(f'No {len(t) - a}')

1040 有几个PAT

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import bisect
s = input()
p, a, pa, t = [], [], [], []
for idx, char in enumerate(s):
if char == 'P':
p.append(idx)
elif char == 'A':
a.append(idx)
elif char == 'T':
t.append(idx)
tmp = 0
for i in a:
x = bisect.bisect(p, i)
tmp += x
pa.append(tmp)
res = 0
for i in t:
x = bisect.bisect(a, i)
if x:
res += pa[x-1]
print(res % 1000000007)

1041 考试座位号

1
2
3
4
5
6
7
8
9
n = int(input())
nums = [0] * 10001
for _ in range(n):
a, b, c = map(int, input().split())
nums[b] = (a, c)
m = int(input())
inqurie = map(int, input().split())
for i in inqurie:
print(nums[i][0], nums[i][1])

1042 字符统计

1
2
3
4
5
6
7
8
9
10
11
from collections import Counter
s = input()
t = []
for char in s:
if 65 <= ord(char) <= 90:
char = char.lower()
if 97 <= ord(char) <= 122:
t.append(char)
t.sort()
t = Counter(t)
print(t.most_common(1)[0][0], t.most_common(1)[0][1])

1043 输出PATest

1
2
3
4
5
6
7
8
9
10
11
from collections import Counter
s = input()
t = [char for char in s if char in 'PATest']
counter = Counter(t)
res = ''
for _ in range(counter.most_common(1)[0][1]):
for char in 'PATest':
if counter[char]:
counter[char] -= 1
res += char
print(res)

1044 火星数字

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
n = int(input())
units = ['tret', 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jly', 'aug', 'sep', 'oct', 'nov', 'dec']
tens = ['tam', 'hel', 'maa', 'huh', 'tou', 'kes', 'hei', 'elo', 'syy', 'lok', 'mer', 'jou']
for _ in range(n):
a = input()
try:
a = int(a)
except ValueError:
if len(a) > 4:
x, y = a.split()
ten, unit = tens.index(x) + 1, units.index(y)
print(ten * 13 + unit)
else:
if a in units:
print(units.index(a))
else:
print((tens.index(a) + 1) * 13)
else:
unit, ten = a % 13, a // 13
if ten > 0 and unit > 0:
print(tens[ten - 1], units[unit])
elif ten > 0:
print(tens[ten - 1])
else:
print(units[unit])

1045 快速排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
n = int(input())
nums = list(map(int, input().split()))
lefts, rights, res = [], [], []
left, right = 0, float('inf')
for num in nums:
if left < num:
left = num
lefts.append(left)
for num in nums[::-1]:
if right > num:
right = num
rights.append(right)
for left, num, right in zip(lefts, nums, rights[::-1]):
if left <= num <= right:
res.append(num)
print(len(res))
print(' '.join(map(str, res)))

1046 划拳

1
2
3
4
5
6
7
8
9
10
11
n = int(input())
a = b = 0
for _ in range(n):
x1, x2, y1, y2 = map(int, input().split())
if x2 == y2:
continue
if x1 + y1 == x2:
b += 1
elif x1 + y1 == y2:
a += 1
print(a, b)

1047 编程团体赛

1
2
3
4
5
6
7
8
n = int(input())
nums = [0] * 1001
for _ in range(n):
num, score = input().split()
a, b = map(int, num.split('-'))
nums[a] += int(score)
res = max(nums)
print(nums.index(res), res)

1048 数字加密

1
2
3
4
5
6
7
8
9
10
11
12
13
14
a, b = input().split()
l = max(len(a), len(b))
a = list(map(int, a[::-1])) + [0] * (l - len(a))
b = list(map(int, b[::-1])) + [0] * (l - len(b))
dicts = ['J', 'Q', 'K']
res = []
for i in range(l):
if i % 2 == 0:
t = (a[i] + b[i]) % 13
res.append(dicts[t - 10] if t >= 10 else t)
else:
res.append((b[i] - a[i] + 10) % 10)
print(''.join(map(str, res[::-1])))

1049 数列的片段和(部分通过)

1
2
3
4
5
6
7
8
n = int(input())
nums = list(map(float, input().split()))
res, a = 0, 1
for num in nums:
res += num * a * n
n -= 1
a += 1
print(f'{res:.2f}')

1050 螺旋矩阵

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
31
32
33
34
35
36
import math
N = int(input())
nums = list(map(int, input().split()))
nums.sort(reverse=True)
m = n = 0
for i in range(1, int(math.sqrt(N)) + 1):
if N % i == 0:
n, m = i, N // i
res = [[0] * n for _ in range(m)]
u, d, l, r = 0, m, 0, n
idx = 0
while True:
res[u][l:r] = nums[idx: idx+r-l]
u += 1
idx += r-l
if u == d or l == r:
break
for i in range(u, d):
res[i][r-1] = nums[idx]
idx += 1
r -= 1
if u == d or l == r:
break
res[d-1][l:r] = nums[idx: idx+r-l][::-1]
idx += r-l
d -= 1
if u == d or l == r:
break
for i in range(d-1, u-1, -1):
res[i][l] = nums[idx]
idx += 1
l += 1
if u == d or l == r:
break
for row in res:
print(' '.join(map(str, row)))

1051 复数乘法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import math
r1, p1, r2, p2 = map(float, input().split())
a1 = r1 * math.cos(p1)
b1 = r1 * math.sin(p1)
a2 = r2 * math.cos(p2)
b2 = r2 * math.sin(p2)
a3 = a1*a2-b1*b2
b3 = a1*b2+a2*b1
if abs(a3) < 0.005:
a3 = 0
if abs(b3) < 0.005:
print(f'{a3:.2f}+0.00i')
elif b3 > 0:
print(f'{a3:.2f}+{b3:.2f}i')
else:
print(f'{a3:.2f}{b3:.2f}i')

1052 卖个萌

1
看不懂题

1053 住房空置率

1
2
3
4
5
6
7
8
9
10
11
n, e, d = map(float, input().split())
maybe_vacant = vacant = 0
for _ in range(int(n)):
nums = list(map(float, input().split()))
t = sum(1 for i in nums[1:] if i < e)
if t / nums[0] > 0.5:
if nums[0] > d:
vacant += 1
else:
maybe_vacant += 1
print(f'{maybe_vacant / n * 100:.1f}% {vacant / n * 100:.1f}%')