64分 求助!

P1104 生日

oKdm @ 2024-03-04 21:01:14

#include <iostream>
using namespace std;

int n,sum[105];

struct date {
    char name[25];
    int y;
    int m;
    int d;
}a[105];

int main(){
    cin >> n;
    for(int i = 1;i <= n; i++){
        cin >> a[i].name >> a[i].y >> a[i].m >> a[i].d;
        sum[i] = a[i].d + a[i].m * 100 + a[i].y * 10000;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1;j <= n - i;j++){
            if(sum[j] >= sum[j+1]){
                swap(sum[j],sum[j+1]);
                swap(a[j].name,a[j+1].name);
            }
        }
    }
    for(int i = 1;i <= n;i++){
        cout << a[i].name << endl;
    }
    return 0;
}

5 #6过不了

代码也满足“如果有两个同学生日相同,输入靠后的同学先输出”啊


by liuzilin114514 @ 2024-03-04 21:04:39

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

@oKdm


by liuzilin114514 @ 2024-03-04 21:05:21

@oKdm 这是我的


by liuzilin114514 @ 2024-03-04 21:06:45

@oKdm 你用的冒泡不会爆吗


by oKdm @ 2024-03-04 21:08:31

自测输入输出⬇️

输入#1

2
a 2000 1 1
b 2000 1 1

输出#1

b a

输入#1

3
a 2000 1 1
b 2000 1 1
c 2000 1 1

输出#1

c
b
a

by liuzilin114514 @ 2024-03-04 21:09:52

@oKdm https://www.luogu.com.cn/record/147364232 AC记录


by kennnyisclever @ 2024-03-04 21:10:05

asdfghjkl


by oKdm @ 2024-03-06 21:48:52

@liuzilin114514 没有爆,是WA,而且我下载测试点之后看到程序输出了最后几行


|