13,825
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include<string>
using namespace std;
struct Student{
public:
string name;
int score;
};
void changestu(Student &a,Student &b){
Student tmp=a;
a=b;
b=tmp;
}
int main()
{
Student stu[1000];
int n=0;
int flag=0;
while(cin>>n>>flag){
for(int i=0;i<n;i++)
cin>>stu[i].name>>stu[i].score;
if(flag==0){
for(int p=0;p<n;p++){
for(int q=p+1;q<n;q++){
if(stu[p].score<stu[q].score){
changestu(stu[p],stu[q]);
}
}
}
}else{
for(int p=0;p<n;p++){
for(int q=p+1;q<n;q++){
if(stu[p].score>stu[q].score){
changestu(stu[p],stu[q]);
}
}
}
}
for(int r=0;r<n;r++)
cout<<stu[r].name<<' '<<stu[r].score<<endl;
}
}
28
1
qhsq 15
ozslg 79
ncttmtsphb 71
a 39
eeiuyzsj 34
nmlrokx 21
pjizylo 90
ec 45
f 12
sh 31
fm 25
ptprphubqk 29
wxdiwv 0
uhlcpjtxad 60
w 20
zwktbpun 70
efzfkf 69
v 31
rsnrgtl 73
lhdo 76
wt 56
mcdwd 14
ydrnoyd 37
gmlfds 76
zx 1
dqx 98
gz 90
kvbzrwrrjj 13
wxdiwv 0
zx 1
f 12
kvbzrwrrjj 13
mcdwd 14
qhsq 15
w 20
nmlrokx 21
fm 25
ptprphubqk 29
v 31