样例过了,提交0分

P1104 生日

LHX_18460366315 @ 2024-02-06 12:56:20

上面的样例是过了的,但提交后却是0分。

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,y[105],m[105],d[105];
    string s[105];
    cin >> n;
    for (int i = 1;i <= n;i++){
        cin >> s[i] >> y[i] >> m[i] >> d[i];
    }
    for (int i = 1;i <= n;i++){
        for (int j = i + 1;j <= n;j++){
            if (y[i] > y[j]){
                swap(s[i],s[j]);
            }else if (y[i] == y[j]){
                if (m[i] > m[j]){
                    swap(s[i],s[j]);
                }else if (m[i] == m[j]){
                    if (d[i] >= d[j]){
                        swap(s[i],s[j]);
                    }
                }
            }
        }
    }
    for (int i = 1;i <= n;i++){
        cout << s[i] << endl;
    }
    return 0;
}

by ikun_god @ 2024-02-06 13:06:01

@ZZYX_18670145320

哪需要这么麻烦,直接万能的STL不就行了吗?

#include<bits/stdc++.h>
using namespace std;
struct node{
    string name;
    int y,m,d;
    int i_x;
}a[111];
bool cmp(node a,node b){
    if (a.y==b.y){
        if (a.m==b.m){
            if (a.d==b.d){
                return a.i_x>b.i_x;
            }else{
                return a.d<b.d;
            }
        }else{
            return a.m<b.m;
        }
    }else{
        return a.y<b.y;
    }
}
int main(){
    int n;
    cin>>n;
    for (int i=0;i<n;++i){
        cin>>a[i].name>>a[i].y>>a[i].m>>a[i].d;
        a[i].i_x=i;
    }
    sort(a,a+n,cmp);
    for (int i=0;i<n;++i){
        cout<<a[i].name<<endl;
    }
}

by LHX_18460366315 @ 2024-02-06 18:20:58

@ikun_god 谢谢


|