文章
79
粉丝
221
获赞
46
访问
198.4k
#include <iostream>
#include <string>
using namespace std;
typedef struct stu {
string name;
float sco;
struct stu* next;
}sn, * SL;
int main() {
int n, flag;
while (cin >> n >> flag) {
SL S = new sn;
S->next = NULL;
for (int i = 0; i < n; i++) {
sn* k = new sn, * p = S;
cin >> k->name >> k->sco;
if (flag == 1) {
while (p->next != NULL) {
if (p->next->sco > k->sco)
break;
p = p->next;
}
k->next = p->next;
p->next = k;
}
else {
while (p->next != NULL) {
if (p->next->sco < k->sco)
break;
p = p->next;
}
k->next = p->next;
p->next = k;
}
}
S = S->next;
while (S) {
cout << S->name << " " << S->sco << endl;
S = S->next;
}
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发