P5723
完整代码
def is_prime(y):if y < 2:return Falsefor i in range(2, int(y**0.5) + 1):if y % i == 0:return Falsereturn Truen = int(input())
sum_primes = 0
x = 0if n < 2:print("0")
elif n == 2:print("2\n1")
else:for i in range(2, n + 1):if i % 2 == 0 and i != 2:continueif sum_primes + i > n:print(x)breakif is_prime(i):print(i)sum_primes += ix += 1
P5728
完整代码
def f(x, y): # 判断上下各门之差return abs(x - y)n = int(input())
s = []for i in range(n):c, m, e = map(int, input().split())total_sum = c + m + e # 计算每个人的分数和s.append({'c': c, 'm': m, 'e': e, 'sum': total_sum})ans = 0
for i in range(n):for j in range(i + 1, n):if (f(s[i]['c'], s[j]['c']) <= 5 andf(s[i]['e'], s[j]['e']) <= 5 andf(s[i]['m'], s[j]['m']) <= 5 andf(s[i]['sum'], s[j]['sum']) <= 10): # 符合条件,ans++ans += 1print(ans)
P1428
完整代码
n = int(input())
a = list(map(int, input().split()))
sum_arr = [0] * n # 初始化sum数组为0for i in range(1, n):for j in range(i, 0, -1):if a[i] > a[j - 1]:sum_arr[i] += 1print(' '.join(map(str, sum_arr))) # 输出
P1319
完整代码
# 获取输入
inputs = list(map(int, input().strip().split()))# 提取矩阵大小
n = inputs[0]
compressed = inputs[1:]result = ""# 开始解压
current_char = "0"
for count in compressed:result += current_char * count# 切换当前字符current_char = "1" if current_char == "0" else "0"# 将结果输出为的矩阵
for i in range(n):print(result[i * n:(i + 1) * n])