问题标题: 酷町堂:1491

0
0
周睿洋
周睿洋
新手守护
新手守护
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <ctime>
#include <climits>
using namespace std;

struct node {
    string name;
    int y, m, d;
} a[105];

bool cmp(node x, node y) {
    if(x.y!=y.y) {
        return x.y<y.y;
    } else if(x.m!=y.m) {
        return x.m<y.m;
    } else if(x.d!=y.d) {
        return x.d<y.d;
    } else if(x.name.size()!=y.name.size()) {
        return x.name.size()<y.name.size();
    } else {
        return x.name<y.name;
    }
}

int n;
bool flag = true;

int main() {
    cin >> n;
    for(int i=1; i<=n; i++) {
        cin >> a[i].name >> a[i].y >> a[i].m >> a[i].d;
    }
    sort(a+1, a+n+1, cmp);
    for(int i=2; i<=n; i++) {
        if(a[i].y==a[i-1].y && a[i].m==a[i-1].m && a[i].d==a[i-1].d) {
            flag = false;
            printf("%02d ", a[i].y);
            cout << a[i].m << " " << a[i].d << " " << a[i-1].name << " ";
            while(a[i].y==a[i-1].y && a[i].m==a[i-1].m && a[i].d==a[i-1].d) {
                cout << a[i].name << " ";
                i ++;
            }
            cout << endl;
        }
    }
    if(flag) {
        cout << "No";
    }
    return 0;
}

 


2
1
1
1
0
0
0
while
while
高级光能
高级光能

最好分成几个cmp函数来写

0
0
0
0
0
张天璨
张天璨
新手天翼
新手天翼

代码本身就是对的,鳖闹!

我要回答