我明明对了,偏偏WA0分,求解释

P1104 生日

Lazy_make_name @ 2024-03-25 23:08:20

样例输入: 5

Wangxing 1992 1 9

Liyue 1990 12 11

Pengwei 1991 10 10

Mating 1993 1 2

Chenya 1994 5 7 样例输出: Liyue

Pengwei

Wangxing

Mating

Chenya (请忽视中间的空行,格式要求被迫写的) 我的输出:

Liyue

Pengwei

Wangxing

Mating

Chenya

代码:

#include<iostream>
using namespace std;
string x[101];
int v[3][101],n;
void huan(int a,int b){
    string li;
    int li1;
    li=x[a];
    x[a]=x[b];
    x[b]=li;
    for(int k=0;k<=2;k++){
        li1=v[k][a];
        v[k][a]=v[k][b];
        v[k][b]=li1;
    }
    return;
}
bool pan(int a,int b){
    if(v[0][a]!=v[0][b])
        return v[0][a]>v[0][b];
    if(v[1][a]!=v[1][b])
        return v[1][a]>v[1][b];
    return v[2][a]>v[2][b];
}
int main(){
    cin>>n; 
    for(int i=1;i<=n;i++)
        cin>>x[i]>>v[0][i]>>v[1][i]>>v[2][i];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n-i+1;j++){
            if(pan(j,j+1))
                huan(j,j+1);
        }
    }
    for(int i=1;i<=n;i++)
        cout<<x[i]<<endl;
    cout<<x[n+1];
}

by _buzhidao_ @ 2024-03-26 07:01:00

@13860121259AaBb

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

by _buzhidao_ @ 2024-03-26 07:02:24

@13860121259AaBb 您的 pan 函数应该写错了


|