题解 | #成绩排序#
成绩排序
http://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b
c++
using namespace std;
bool cmp0(pair<string ,int>a,pair<string,int>b){
return a.second>b.second;
}
bool cmp1(pair<string ,int>a,pair<string,int>b){
return a.second<b.second;
}
int main(){
int n1,n2;
while(cin>>n1>>n2){
vector<pair<string,int>>v;
for(int i=0;i<n1;i++){
string s1;
int a;
cin>>s1>>a;
v.push_back({s1,a});
}
//升序
if(n2==1){
stable_sort(v.begin(), v.end(),cmp1);
}else stable_sort(v.begin(), v.end(),cmp0);
for(int i=0;i<v.size();i++){
cout<<v[i].first<<" "<<v[i].second<<endl;
}
// puts(" ");
}
return 0;
}