'commit'
This commit is contained in:
33
TangDou/XiTi/1357.cpp
Normal file
33
TangDou/XiTi/1357.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
struct Student {
|
||||
string num;
|
||||
float score;
|
||||
};
|
||||
|
||||
//对比的方法
|
||||
/*
|
||||
用大于号就是从大到小排序,用小于号就是从小到大排序
|
||||
*/
|
||||
bool compare(const Student &x, const Student &y) {
|
||||
return x.score > y.score;
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
int n, k;
|
||||
cin >> n >> k;
|
||||
//创建动态数组
|
||||
Student *s = new Student[n];
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cin >> s[i].num >> s[i].score;
|
||||
}
|
||||
//排序
|
||||
sort(s, s + n, compare);
|
||||
//输出
|
||||
cout << s[k - 1].num << " " << s[k - 1].score << endl;
|
||||
//释放内存
|
||||
delete[]s;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user