C4天梯赛练习总结 (20210302-20210303)
作者:互联网
题目链接:团体程序设计天梯赛-练习集
L1-005 考试座位号
语言:Python (python3)
N = int(input())
d = {}
for i in range(N):
info = input().split()
d[int(info[1])] = info[0] + ' ' + info[2]
M = int(input())
nums = list(map(int, input().split()))
for i in range(M):
num = nums[i]
print(d[num])
L1-006 连续因子
语言:C (clang)
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
bool isPrime(int n) {
if (n == 2) {
return true;
} else {
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
}
int main(void) {
int N;
scanf("%d", &N);
if (isPrime(N)) {
printf("1\n%d\n", N);
} else {
int ans;
int start;
for (int i = 2; i <= sqrt(N); i++) {
if (N % i != 0) {
continue;
}
int t = i;
int cnt = 1;
for (int j = i + 1; j <= sqrt(N); j++) {
t *= j;
if (N % t != 0) {
break;
}
cnt++;
}
if (cnt > ans) {
ans = cnt;
start = i;
}
}
printf("%d\n", ans);
for (int i = start; i < start + ans; i++) {
if (i != start) {
printf("*");
}
printf("%d", i);
}
printf("\n");
}
return 0;
}
L1-016 查验身份证
语言:Python (python3)
def check(n):
s = 0
w = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
for i in range(17):
t = int(n[i])
s += t * w[i]
dic = {0: '1', 1: '0', 2: 'X', 3: '9', 4: '8', 5: '7', 6: '6',
7: '5', 8: '4', 9: '3', 10: '2'}
return n[-1] == dic[s % 11]
N = int(input())
nums = [input() for i in range(N)]
ans = []
for i in range(N):
flag = 0
for j in range(17):
if nums[i][j] < '0' or nums[i][j] > '9':
ans.append(nums[i])
flag = 1
break
if flag == 0 and not check(nums[i]):
ans.append(nums[i])
continue
if len(ans) == 0:
print('All passed')
else:
for i in range(len(ans)):
print(ans[i])
L1-017 到底有多二
语言:Python (python3)
N = input()
length = len(N)
isNegative = False
isEven = False
if N[0] == '-':
length -= 1
isNegative = True
N = N[1:]
if N[-1] in '02468':
isEven = True
cnt = 0
for i in N:
if i == '2':
cnt += 1
cnt /= length
if isNegative:
cnt *= 1.5
if isEven:
cnt *= 2
print('{:.2f}%'.format(cnt * 100))
L1-018 大笨钟
语言:Python (python3)
time = input().split(':')
h = int(time[0])
m = int(time[1])
if h < 12 or (h == 12 and m == 0):
print('Only {}:{}. Too early to Dang.'.format(time[0], time[1]))
else:
h -= 12
if m != 0:
h += 1
print('Dang' * h)
L1-022 奇偶分家
语言:Python (python3)
N = int(input())
nums = list(map(int, input().split()))
cnt1, cnt2 = 0, 0
for i in range(N):
if nums[i] % 2 == 0:
cnt2 += 1
else:
cnt1 += 1
print('{} {}'.format(cnt1, cnt2))
L1-031 到底是不是太胖了
语言:C++ (g++)
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
while (N--) {
double H, W;
cin >> H >> W;
W /= 2;
double W_std = 0.9 * (H - 100);
if (fabs(W - W_std) < W_std * 0.1) {
cout << "You are wan mei!" << endl;
} else {
if (W < W_std) {
cout << "You are tai shou le!" << endl;
} else {
cout << "You are tai pang le!" << endl;
}
}
}
return 0;
}
L1-035 情人节
语言:Python (python3)
names = []
while True:
name = input()
if name != '.':
names.append(name)
else:
break
if len(names) >= 14:
print('{} and {} are inviting you to dinner...'.format(names[1], names[13]))
elif 2 <= len(names) < 14:
print('{} is the only one for you...'.format(names[1]))
else:
print('Momo... No one is for you ...')
L1-056 猜数字
语言:Python (python3)
import math
N = int(input())
s = 0
dic = {}
for i in range(N):
guess = input().split()
guess[1] = int(guess[1])
s += guess[1]
dic[guess[0]] = guess[1]
s //= N * 2
for key in dic.keys():
dic[key] = math.fabs(s - dic[key])
print(s, sorted(dic.items(), key=lambda x: x[1])[0][0])
L1-059 敲笨钟
语言:Python (python3)
N = int(input())
for i in range(N):
s = input().split(',')
if s[0][-3:] == 'ong' and s[1][-4:-1] == 'ong':
s[1] = s[1].replace(' '.join(s[1].split()[-3:]), 'qiao ben zhong.')
print(','.join(s))
else:
print('Skipped')
标签:20210302,20210303,cnt,int,range,ans,print,input,C4 来源: https://blog.csdn.net/qq_45554010/article/details/114330024