补全9月11日至13日课评:为13名学生创建请假文档,为5个班级创建总结文档
This commit is contained in:
38
C++代码/CSP04/02-简单排序/05成绩排名.cpp
Normal file
38
C++代码/CSP04/02-简单排序/05成绩排名.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
string name[100100];
|
||||
int score[100100];
|
||||
|
||||
void bubble(int n){
|
||||
for(int i = 1; i <= n - 1; i++){ // ÌË´Î
|
||||
bool bol = true; // ÈÏΪÅźÃÐòÁË
|
||||
for(int j = 1; j <= n - i; j++){
|
||||
if(score[j] < score[j+1]){
|
||||
bol = false;
|
||||
swap(score[j], score[j+1]);
|
||||
swap(name[j], name[j+1]);
|
||||
}
|
||||
}
|
||||
if(bol){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
cin >> n;
|
||||
for(int i = 1; i <= n; i++){
|
||||
cin >> name[i] >> score[i];
|
||||
}
|
||||
|
||||
bubble(n);
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
cout << name[i] << " " << score[i] << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user