为什么WA
  • 板块P1104 生日
  • 楼主dghcs
  • 当前回复4
  • 已保存回复4
  • 发布时间2022/11/22 20:44
  • 上次更新2023/10/27 01:54:25
查看原帖
为什么WA
142720
dghcs楼主2022/11/22 20:44

这个比较函数有什么问题吗?为什么WA了啊

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
struct stu{
    string name;
    int year;
    int month;
    int day;
}a[105];
bool cmp(stu a,stu b)
{
    if(a.year > b.year)
        return true;
    else if(a.year == b.year && a.month > b.month)
        return true;
    else if(a.month == b.month && a.day > b.day)
        return true;
    else
        return false;;
}
int main()
{
    int n;cin >> n;
    for(int i = 1;i <= n;i++)
        cin >> a[i].name >> a[i].year >> a[i].month >> a[i].day;
    sort(a+1,a+1+n,cmp);
    for(int i = n;i >= 1;i--)
        cout << a[i].name << endl;
}

2022/11/22 20:44
加载中...