就最后一个样例没过,谁能帮我看看,谢谢啦

P1104 生日

ruanertanjing @ 2024-08-09 15:59:32

// P1104 生日
// https://www.luogu.com.cn/problem/P1104

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <functional>
#include <climits>

#define quickio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl "\n"

using namespace std;
typedef long long ll;

struct Stu
{
    string name;
    int year;
    int month;
    int day;
};

bool cmp(Stu s1, Stu s2)
{
    if (s1.year != s2.year)
        return s1.year < s2.year;
    if (s1.month != s2.month)
        return s1.month < s2.month;
    if (s1.day != s2.day)
        return s1.day < s2.day;

    return false;/**/
}

void solve()
{
    int n;
    cin >> n;
    vector<Stu>v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i].name >> v[i].year >> v[i].month >> v[i].day;
    }
    sort(v.begin(), v.end(), cmp);
    for (int i = 0; i < n; i++)
    {
        cout << v[i].name << endl;
    }
}

int main()
{
    solve();
    return 0;
}

by w13675481318 @ 2024-08-10 22:27:52

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
struct x{
    string s;
    int y,m,d,top;
}a[105];
bool cmp(x a,x b){
    if(a.y<b.y||a.y==b.y&&a.m<b.m||a.y==b.y&&a.m==b.m&&a.d<b.d||a.y==b.y&&a.m==b.m&&a.d==b.d&&a.top>b.top){
        return 1;
    }
    else{
        return 0;
    }
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i].s>>a[i].y>>a[i].m>>a[i].d;
        a[i].top=i;
    }
    sort(a,a+n,cmp);
    for(int i=0;i<n;i++){
        cout<<a[i].s<<endl;
    }
    return 0;
}

by w13675481318 @ 2024-08-10 22:29:23

不高级的代码但非常简单易懂↑


|