0分,求指点(P1104)

P1104 生日

Zhc13909022402 @ 2024-06-26 10:33:07

#include <bits/stdc++.h>
using namespace std;
struct node
{
    char name;
    int year;
    int month;
    int day;
}a[1010];
bool cmp(node x,node y)
{
    if(x.year!=y.year) return x.year<y.year;
    else if(x.month>y.month) return x.month<y.month;
    else if(x.day!=y.day) return x.day<y.day;
    else return x.name>y.name;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i].name>>a[i].year>>a[i].month>>a[i].day;
    }
    sort(a,a+n,cmp);
    for(int i=0;i<n;i++)
    {
        cout<<a[i].name<<endl;
    }
    return 0;
}

by Zhc13909022402 @ 2024-06-26 10:33:40

P1104


by shentianxing @ 2024-06-26 10:42:25

“char name;”


by ytr2010 @ 2024-06-26 10:52:24

@Zhc13909022402 你家人名一个字符?


by wzhmyt @ 2024-06-26 11:22:46

#include<bits/stdc++.h>
using namespace std;
struct node
{
    string s;
    int n{},y{},r{},num{};
}a[110];
int n;
bool cmp(const node& a,const node& b)
{
    if(a.n<b.n)return true;
    if(a.n>b.n)return false;
    if(a.n==b.n)
    {
        if(a.y<b.y)return true;
        if(a.y>b.y)return false;
        if(a.y==b.y)
        {
            if(a.r<b.r)return true;
            if(a.r>b.r)return false;
            if(a.r==b.r)
            {
                if(a.num>b.num)return true;
                else return false;
            }
        }
    }
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i].s>>a[i].n>>a[i].y>>a[i].r,a[i].num=i;
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++)cout<<a[i].s<<endl;
    return 0;
}

by adminh @ 2024-06-26 11:26:45

#include <bits/stdc++.h>
using namespace std;
struct node
{
    string name;
    int year;
    int month;
    int day;
    int h;//定义输入顺序
}a[1010];
bool cmp(node x,node y)
{
    if(x.year!=y.year) return x.year<y.year;
    else if(x.month!=y.month) return x.month<y.month;
    else if(x.day!=y.day) return x.day<y.day;
    else return x.h>y.h;//序号靠后的先输出
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i].name>>a[i].year>>a[i].month>>a[i].day;
  a[i].h=i;//储存
    }
    sort(a,a+n,cmp);
    for(int i=0;i<n;i++)
    {
        cout<<a[i].name<<endl;
    }
    return 0;
}

亲测AC


by adminh @ 2024-06-26 11:27:07

@Zhc13909022402


by Zhc13909022402 @ 2024-06-26 16:41:58

谢各位大佬,小的受益匪浅


|