C4天梯赛练习总结 (20210304)

题目链接:团体程序设计天梯赛-练习集

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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值