团体程序设计天梯赛-练习集L1-031~040

酶和ATP 2022年04月04日 643次浏览

L1-031 到底是不是太胖了

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

int n;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        float h, w;
        cin >> h >> w;
        float s = 2 * (h - 100) * 0.9;

        if (abs(s - w) < s * 0.1)
            cout << "You are wan mei!" << endl;
        else if (w <= s)
            cout << "You are tai shou le!" << endl;
        else
            cout << "You are tai pang le!" << endl;
    }

    return 0;
}

L1-032 Left-pad

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

int n;
string c;
string s;

int main() {
    cin >> n >> c;
    getline(cin, s);
    getline(cin, s);
    if (s.size() > n) {
        // 切除
        s = s.substr(s.size() - n);
    } else {
        // 补充
        int t = n - s.size();
        for (int i = 0; i < t; i++) s = c + s;
    }
    cout << s << endl;
    return 0;
}

L1-033 出生年

#include <algorithm>
#include <cstring>
#include <iostream>
#include <set>
using namespace std;
int y, n;

bool check(int y1) {
    set<char> s;
    string year = to_string(y1);
    if (year.size() == 3)
        year = "0" + year;
    else if (year.size() == 2)
        year = "00" + year;
    else if (year.size() == 1)
        year = "000" + year;
    for (int i = 0; i < 4; i++) s.insert(year[i]);
    if (s.size() == n) {
        cout << y1 - y << ' ' << year << endl;
        return true;
    }
    return false;
}

int main() {
    cin >> y >> n;
    for (int i = y; i < 9999; i++) {
        if (check(i)) break;
    }
    return 0;
}

L1-034 点赞

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
int n, m;
int maxn = -0x3f3f3f3f, maxid = -0x3f3f3f3f;
map<int, int> ma;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> m;
        int id;
        for (int j = 0; j < m; j++) {
            cin >> id;
            ma[id]++;
            if ((ma[id] > maxn) || (ma[id] == maxn && id > maxid)) {
                maxn = ma[id];
                maxid = id;
            }
        }
    }

    cout << maxid << ' ' << maxn << endl;

    return 0;
}

L1-035 情人节

#include <algorithm>
#include <cstring>
#include <iostream>
#include <set>
using namespace std;
int y, n;

bool check(int y1) {
    set<char> s;
    string year = to_string(y1);
    if (year.size() == 3)
        year = "0" + year;
    else if (year.size() == 2)
        year = "00" + year;
    else if (year.size() == 1)
        year = "000" + year;
    for (int i = 0; i < 4; i++) s.insert(year[i]);
    if (s.size() == n) {
        cout << y1 - y << ' ' << year << endl;
        return true;
    }
    return false;
}

int main() {
    cin >> y >> n;
    for (int i = y; i < 9999; i++) {
        if (check(i)) break;
    }
    return 0;
}

L1-036 A乘以B

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}

L1-037 A除以B

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (b == 0) cout << a << "/0=Error";
    if (b < 0) printf("%d/(%d)=%.2f", a, b, (float)a / b);
    if (b > 0) printf("%d/%d=%.2f", a, b, (float)a / b);
    cout << endl;
    return 0;
}

L1-038 新世界

#include <iostream>
using namespace std;

int main() {
    cout << "Hello World" << endl;
    cout << "Hello New World" << endl;
    return 0;
}

L1-039 古风排版

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 110;
int n;
string s;
char c[N][N];

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    getline(cin, s);
    getline(cin, s);
    // 看看有多少行,要上取整
    int num = ceil(1.0 * s.size() / n);
    int cnt = 0;
    for (int i = num; i > 0; i--)
        for (int j = 1; j <= n; j++) {
            if (cnt >= s.size())
                c[j][i] = ' ';
            else
                c[j][i] = s[cnt++];
        }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= num; j++) {
            cout << c[i][j];
        }
        cout << endl;
    }

    return 0;
}

L1-040 最佳情侣身高差

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;
int n;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        char a;
        double b;
        cin >> a >> b;
        if (a == 'F')
            printf("%.2f\n", b * 1.09);
        else
            printf("%.2f\n", b / 1.09);
    }
    return 0;
}