ssdhnd @ 2024-10-03 22:31:32
鄙人代码:
#include<bits/stdc++.h>
using namespace std;
int n;
struct Node{
string name;
int n,y,r,num;
}a[105];
bool cmp(Node a,Node b){
if(a.n<b.n){
return 1;
}
else if(a.n==b.n&&a.y<b.y){
return 1;
}
else if(a.n==b.n&&a.y<b.y&&a.r<b.r){
return 1;
}
else if(a.n==b.n&&a.y<b.y&&a.r<b.r&&a.num>b.num){
return 1;
}
else{
return 0;
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].name>>a[i].n>>a[i].y>>a[i].r;
a[i].num=i;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++){
cout<<a[i].name<<'\n';
}
return 0;
}
样例过了
by Lisuyang @ 2024-10-03 22:50:29
@ssdhnd
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 6;
int n;
struct Student{
string s;
int y, m, d, num;
bool operator< (const Student& B) const {
return B.y > y || ((B.y == y) && B.m > m)
|| ((B.y == y) && (B.m == m) && B.d > d)
|| ((B.y == y) && (B.m == m) && (B.d == d) && B.num < num);
}
}stu[N];
int main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
for(int i = 1; i <= n; ++ i) cin >> stu[i].s >> stu[i].y >> stu[i].m >> stu[i].d, stu[i].num = i;
sort(stu + 1, stu + 1 + n);
for(int i = 1; i <= n; ++ i) cout << stu[i].s << '\n';
return 0;
}
by ssdhnd @ 2024-10-03 22:53:10
@Lisuyang 感谢已关
by Lisuyang @ 2024-10-03 22:53:13
其次 你的cmp写错了(大概是复制的时候忘把 > 改成 == 了) 应为:
bool cmp(Node a,Node b){
if(a.n<b.n){
return 1;
}
else if(a.n==b.n&&a.y<b.y){
return 1;
}
else if(a.n==b.n&&a.y==b.y&&a.r<b.r){
return 1;
}
else if(a.n==b.n&&a.y==b.y&&a.r==b.r&&a.num>b.num){
return 1;
}
else{
return 0;
}
}
by Lisuyang @ 2024-10-03 22:54:32
@ssdhnd 看上一条
by ssdhnd @ 2024-10-03 23:05:47
@Lisuyang
emmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm...(此处省略