心态崩了啊!!!

P1104 生日

iqiqiqiqiqiqiqiq @ 2024-06-21 21:54:31

好多次了,一直RE,好烦

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

有问题吗...


by Fish_Love_Water @ 2024-06-21 22:01:27

@CEFqwq 函数原本是返回0或1,但是好像有<=之后就不知道返回什么了,我记得以前有哪位大佬帖子有提


by CEFqwq @ 2024-06-21 22:03:11

thx


by Fish_Love_Water @ 2024-06-21 22:04:09

@Special_Tony 喔喔喔!我排序代码跟他不一样,抱歉 @iqiqiqiqiqiqiqiq


by Special_Tony @ 2024-06-21 22:08:35

@Steve_xh 好像雀食,但反正stable_sort不常用而且写<=也没啥用,反正我不用。。

洛谷IDE c++14+O2测试结果:

sort:RE

# include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair <int, int> pii;

int a[100005];

bool cmp (const int& x, const int& y) {

    return x <= y;

}

int main () {

    ios::sync_with_stdio (0);

    cin.tie (0);

    cout.tie (0);

    fill (a, a + 100000, 1);

    sort (a, a + 100000, cmp);

    return 0;

}

stable_sort:√

# include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair <int, int> pii;

int a[100005];

bool cmp (const int& x, const int& y) {

    return x <= y;

}

int main () {

    ios::sync_with_stdio (0);

    cin.tie (0);

    cout.tie (0);

    fill (a, a + 100000, 1);

    stable_sort (a, a + 100000, cmp);

    return 0;

}

by iqiqiqiqiqiqiqiq @ 2024-06-22 13:52:34

@Fish_Love_Water 我只是用cmp的时候发现好像倒序,所以反过来


by iqiqiqiqiqiqiqiq @ 2024-06-22 13:53:19

@Steve_xh 用过,炸了2.0


by iqiqiqiqiqiqiqiq @ 2024-06-22 13:54:29

@Special_Tony 刚试了一下,还是炸了


上一页 |