社区讨论

蒟蒻求助,代码特短,感觉自己的cmp函数没写错,但就是WA. QAQ 55555

P1104生日参与者 3已保存回复 8

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
8 条
当前快照
1 份
快照标识符
@lodqwowg
此快照首次捕获于
2023/10/31 11:04
2 年前
此快照最后确认于
2023/11/07 01:34
2 年前
查看原帖
代码如下:
C
#define MAX_VAL 100+5
#include <bits/stdc++.h>
using namespace std;
int n,m;
class student{
    public:
    int id,year,mooth,day;
    string name;
};
student stus[MAX_VAL];

bool cmp(student& a,student& b){
    if(a.year!=b.year) return a.year<b.year;
    if(b.mooth!=b.mooth) return a.mooth<b.mooth;
    if(a.day!=b.day) return a.day<b.day;
    return a.id>b.id;
}


int main(int arg,char **argv){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>stus[i].name;
        cin>>stus[i].year>>stus[i].mooth>>stus[i].day;
        stus[i].id = i;
    }
    sort(stus,stus+n,cmp);
    for(int i=0;i<n;i++)
        cout<<stus[i].name<<endl;
    return 0;
}

回复

8 条回复,欢迎继续交流。

正在加载回复...