求助,编译错误

P1104 生日

@[JMCJimmyMaker](/user/775490) 您对结构体进行了排序,但它不知道怎么排序。 所以请您写重载运算符或 `cmp`。
by tbdsh @ 2023-02-12 12:50:50


```cpp sort(a + 1, a + n + 1); ``` 给结构体排序的时候没有cmp或重载运算符怎么行呢?
by SovLite @ 2023-02-12 12:55:56


@[JMCJimmyMaker](/user/775490) 写cmp函数或者在结构体里写重载运算符
by 50lty12 @ 2023-02-12 13:46:07


# 最后一个测试点有同年同月同日的 # [博客主页](https://www.ricemoon.cn/) ```cpp #include <bits/stdc++.h> using namespace std; #define LL long long #define endl "\n" const int N = 1e5 + 10; const int M = 110; int n; vector<string> s; int year[N], month[N], day[N]; int cnt = 0; bool cmp(int x, int y) { if (year[x] != year[y]) return year[x] < year[y]; else { if (month[x] != month[y]) return month[x] < month[y]; else { if (day[x] != day[y]) return day[x] < day[y]; else return x > y; } } } void solve() { cin >> n; int a[N]; for (int i = 0; i < n; i ++ ) { string s2; cin >> s2; s.push_back(s2); cin >> year[cnt] >> month[cnt] >> day[cnt]; ++ cnt; } for (int i = 0; i < n; i ++ ) a[i] = i; sort(a, a + n, cmp); for (int i = 0; i < n; i ++ ) { cout << s[a[i]] << endl; } } int main() { ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; } ```
by Roger_Spencer @ 2023-02-19 16:05:12


好的,谢谢,此帖结
by JMCJimmyMaker @ 2023-07-15 11:19:07


|