80

P1104 生日

Lawrance_C @ 2024-04-20 11:35:27

#include<bits/stdc++.h>
using namespace std;

struct People
{
    string name;
    int year;
    int month;
    int day;
    int num;
};
void Output(vector<People> &ps)
{
    for(int i=0; i<ps.size(); i++)  
        cout<<ps[i].name<<endl;
}
bool cmp(People &p1,People &p2)
{
    return   p1.year< p2.year 
         || (p1.year==p2.year && p1.month<p2.month)
         || (p1.year==p2.year && p1.month==p2.month && p1.day<p2.day)
         || (p1.year==p2.year && p1.month==p2.month && p1.day==p2.day && p1.num<p2.num);
}
int main()
{
    int n; cin>>n;
    vector<People> ps(n);
    ps.num=0;
    for(int i=0; i<n; i++)
        cin>>ps[i].name>>ps[i].year>>ps[i].month>>ps[i].day>>ps.num=i; 
    sort(ps.begin(), ps.end(), cmp);
    Output(ps) ;
    return 0;
}a a

by like_1999 @ 2024-05-04 18:42:50

@Lawrance_C 做得好复杂呀


by like_1999 @ 2024-05-04 18:44:36

# include<bits/stdc++.h>
using namespace std;
struct den{
    string b;
    int v, c, x;
}m[100];
int main()
{
    int n;
    cin >> n;
    for (int q = 0 ; q < n ; q++) {
        cin >> m[q].b >> m[q].v >> m[q].c >> m[q].x;    
    }
    for (int q = 0 ; q < n ; q++) {
        for (int w = 0 ; w < n ; w++) {
            if (m[q].v < m[w].v) {
                swap (m[q].v , m[w].v);
                swap (m[q].b , m[w].b);
                swap (m[q].c , m[w].c);
                swap (m[q].x , m[w].x);
            }
            else if (m[q].v == m[w].v && m[q].c < m[w].c) {
                swap (m[q].v , m[w].v);
                swap (m[q].b , m[w].b);
                swap (m[q].c , m[w].c);
                swap (m[q].x , m[w].x);
            }
            else if (m[q].v == m[w].v && m[q].c == m[w].c && m[q].x < m[w].x) {
                swap (m[q].v , m[w].v);
                swap (m[q].b , m[w].b);
                swap (m[q].c , m[w].c);
                swap (m[q].x , m[w].x);
            }
            else if (m[q].v == m[w].v && m[q].c == m[w].c && m[q].x == m[w].x) {
                swap (m[q].v , m[w].v);
                swap (m[q].b , m[w].b);
                swap (m[q].c , m[w].c);
                swap (m[q].x , m[w].x);
            }
        }
    }
    for (int q = 0 ; q < n ; q++) cout << m[q].b << endl;
    return 0;
}

|