Description
小信最近看了看自己的微信,发现自己的微信多了好多好友,想要找个人太不容易了(朋友太多也是错^_^)。于是想给自己的好友排个序,
他给出了两个值,一个是好友亲密度,一个是认识时间(单位年)。首先按照好友亲密度排序(亲密度大的排在前面),如果亲密度相同再按照认识时间排序(认识时间长的排在前面)。
Input
第一行输入一个整数 n(1 < n ≤ 10^5),表示好友个数。
然后后面会有 n 行,每行一个名字(字符长度不超过 20)和两个数字 s,y。 s(1 ≤ s ≤ 5)是一个整数代表好友亲密度, y(0 ≤ y ≤ 20) 是一个浮点数代表认识时间,最多只有两位小数。
Output
按照要求排完序后,输出每个人的名字(当亲密度和认识时间都一样的时候,按照名字的字典序)。
Sample Input 1
4
zhangsan 5 10
lisi 1 0.1
wangwu 3 5
zhaoliu 5 10
Sample Output 1
zhangsan
zhaoliu
wangwu
lisi
#include<iostream>
#include<map>
#include<set>
using namespace std;
struct node{
string name;
int s,id;
double y;
bool operator < (const node &a) const{
if(s != a.s){
return s > a.s;
}
if(y != a.y){
return y > a.y;
}
if(name !=a.name){
return name < a.name;
}
return id < a.id;
}
};
int main(){
set<node> st;
int n;
cin >> n;
for(int i=0;i<n;i++){
node x;
cin >> x.name >> x.s >> x.y;
x.id=i;
st.insert(x);
}
set<node> ::iterator it;
for(it = st.begin();it != st.end();it++){
cout << (*it).name<<endl;
}
cout <<endl;
return 0;
}