12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- // Question expression is ambiguous
- // reference: http://acm.hdu.edu.cn/discuss/problem/post/reply.php?postid=20392&messageid=1&deep=0
- #include<iostream>
- #include<vector>
- #include<algorithm>
- using namespace std;
- struct Student {
- int id;
- int score;
- };
- bool compare(Student a, Student b) {
- return a.score > b.score;
- }
- int getRank(int targetScore, vector<Student> students) {
- sort(students.begin(), students.end(), compare);
- int size = students.size();
- int rankNum = 1;
- for (int i = 0; i < size; i++) {
- if (students.at(i).score > targetScore){
- rankNum++;
- }
- else {
- return rankNum;
- }
- }
- return 0;
- }
- int main()
- {
- int targetId = 0, targetScore = 0;
- vector<Student> students;
- int id = 0, score = 0;
- while (cin >> targetId) {
- while (cin >> id >> score)
- {
- if (targetId == id)
- {
- targetScore = score;
- }
- if (id == 0 && score == 0) {
- cout << getRank(targetScore, students) << endl;
- students.clear();
- break;
- }
- students.push_back(Student{ id, score });
- }
- }
- return 0;
- }
|