You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
//结构体
struct Person {
string id ;
int index ;
int age ;
} ;
//对比的方法
/*
用大于号就是从大到小排序,用小于号就是从小到大排序
*/
bool cmp ( const Person & x , const Person & y ) {
//老年人比较
if ( x . age > = 60 & & y . age > = 60 ) {
if ( x . age = = y . age ) {
return x . index < y . index ;
}
return x . age > y . age ;
}
//A是老年人, B是年轻人
if ( x . age > = 60 ) return true ;
//A是年轻人, B是老年人
if ( y . age > = 60 ) return false ;
//都是年轻人
return x . index < y . index ;
}
int main ( ) {
int n ;
cin > > n ;
Person * p = new Person [ n ] ;
for ( int i = 0 ; i < n ; + + i ) {
cin > > p [ i ] . id > > p [ i ] . age ;
p [ i ] . index = i + 1 ;
}
//排序
sort ( p , p + n , cmp ) ;
//输出
for ( int i = 0 ; i < n ; + + i ) {
cout < < p [ i ] . id < < endl ;
}
//删除动态指针数组
delete [ ] p ;
return 0 ;
}