题解 | #成绩排序#
成绩排序
http://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b
include<bits/stdc++.h>
using namespace std;
int main()
{
int n,flag;
while(cin>>n>>flag)
{
string name[n]; int score[n],newscore[n]; for(int i=0;i<n;i++) { cin>>name[i]>>score[i]; newscore[i]=score[i]; } sort(newscore,newscore+n); if(flag==1) { for(int i=0;i<n;i++) { if((newscore[i]==newscore[i+1])&&(i!=n-1)) { continue; } for(int j=0;j<n;j++) { if(newscore[i]==score[j]) { cout<<name[j]<<' '<<score[j]<<endl; } } } } if(flag==0) { for(int i=n-1;i>=0;i--) { if((newscore[i]==newscore[i+1])&&(i!=n-1)) { continue; } for(int j=0;j<n;j++) { if(newscore[i]==score[j]) { cout<<name[j]<<' '<<score[j]<<endl; } } } }
}
return 0;
}