题目链接:团体程序设计天梯赛-练习集
L1-019 谁先倒
语言:C++ (g++)
#include <bits/stdc++.h>
using namespace std;
int arr[100][4];
int main() {
int A_val, B_val;
cin >> A_val >> B_val;
int A_cur = A_val;
int B_cur = B_val;
int N;
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < 4; j++) {
cin >> arr[i][j];
}
}
for (int i = 0; i < N; i++) {
int s = arr[i][0] + arr[i][2];
if (s == arr[i][1] && s == arr[i][3]) {
continue;
} else if (s == arr[i][1]) {
A_cur--;
} else if (s == arr[i][3]) {
B_cur--;
}
if (A_cur < 0) {
cout << "A" << endl << B_val - B_cur << endl;
break;
} else if (B_cur < 0) {
cout << "B" << endl << A_val - A_cur << endl;
break;
}
}
return 0;
}
L1-020 帅到没朋友
语言:C++ (g++)
#include <bits/stdc++.h>
using namespace std;
set<int> ids, ans;
int main() {
int N;
int num;
bool flag = false;
cin >> N;
while (N--) {
int K;
cin >> K;
if (K >= 2) {
while (K--) {
cin >> num;
ids.insert(num);
}
} else {
cin >> num;
}
}
int M;
cin >> M;
while (M--) {
cin >> num;
if (ids.find(num) == ids.end() && ans.find(num) == ans.end()) {
ans.insert(num);
if (flag) {
cout << " ";
}
flag = true;
cout << setw(5) << setfill('0') << num;
}
}
if (!flag) {
cout << "No one is handsome";
}
cout << endl;
return 0;
}
L1-032 Left-pad
语言:Python (python3)
N, ch = input().split()
N = int(N)
s = input()
if len(s) >= N:
print(s[-N:])
else:
num = N - len(s)
s = ch * num + s
print(s)
L1-033 出生年
语言:Python (python3)
year, n = map(int, input().split())
y = str(year)
if len(y) < 4:
y = '0' * (4 - len(y)) + y
cnt = 0
for i in range(year, 3050):
i = str(i)
if len(i) < 4:
i = '0' * (4 - len(i)) + i
if len(set(i)) == n:
print('{} {}'.format(cnt, i))
break
else:
cnt += 1
L1-044 稳赢
语言:Python (python3)
K = int(input())
dic = {'ChuiZi': 'Bu', 'Bu': 'JianDao', 'JianDao': 'ChuiZi'}
a = input()
cnt = 0
while a != 'End':
if cnt == K:
print(a)
cnt = 0
else:
print(dic[a])
cnt += 1
a = input()