P1104 birthday

Title Description

cjfJun want to investigate school OIgroup each student's birthday, and the sort in descending order. But cjfthe king recently a lot of work, no time, so please help her sort.

Input Format

There are 2 2 lines,

The first 1 1 behavior OIof the total number set the n- the n-;

The first 2 lines 2 to n-+. 1 n- + . 1 per row are the name of S S, birth Y Y, month m m, Day D D.

Output Format

There are the n- the n-line,

Namely the n- the n-birthday descending names of the students. (If two students have the same birthday, input by the students after the first output)

Sample input and output

Input # 1
. 3 
Yangchu. 4 1992 23 is 
Qiujingya 1993 10 13 is 
Luowen. 8. 1 1991
Output # 1
Luowen 
Yangchu 
Qiujingya

Description / Tips

Scale data

1<n<1001<n<100

length(s)<20length(s)<20

 

 

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int n;
struct student{
    string name;
    int year,mouth,day;
};
bool comp(const student &a,const student &b){
    if(a.year!=b.year){return a.year<b.year;}
    if(a.mouth!=b.mouth){return a.mouth<b.mouth;}
    if(a.day!=b.day){return a.day<b.day;}
    return true;
}
student a[1000000];
int main(){
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>a[i].name>>a[i].year>>a[i].mouth>>a[i].day;
    }
    stable_sort(a,a+n,comp);
    for(int i=0;i<n;++i){
        cout<<a[i].name<<endl;
    }
    return 0;
}

  

Guess you like

Origin www.cnblogs.com/xiongchongwen/p/11615333.html