// Question expression is ambiguous // reference: http://acm.hdu.edu.cn/discuss/problem/post/reply.php?postid=20392&messageid=1&deep=0 #include #include #include 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 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 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; }