Rank
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4160 Accepted Submission (s): 1616
Problem Descriptionjackson wants to know he rank in the class. The professor has posted a list of student numbers and marks. Compute Jackson ' s rank in class; That's, if he has the top mark (or was tied for the top mark) his rank is 1; If he has the second best mark (or was tied) his rank was 2, and so on.
Inputthe input consist of several test cases. Each case begins with the student number of Jackson, an integer between 10000000 and 99999999. Following the student number is several lines, each containing a student number between 10000000 and 99999999 and a mark Between 0 and 100. A line with a student number and the mark of 0 terminates each test case. There is no more than students in the class, and each have a unique student number.
Outputfor each test case, output a line giving Jackson's rank in the class.
Sample Input
2007010120070102 10020070101 3320070103 2220070106 330 0
Sample Output
2
Source2007 Provincial Training Team Practice (2) The first mistake is the assumption that it is possible for the two people to have the same results. So when searching for the child's score in a ranked score, multiple output positions appear. In fact, you should break when you find it, so you don't have to test for AC.
#include <iostream> #include <algorithm>using namespace std;struct person{int n;int b;} Per[1011];bool CMP (person A,person c) {return a.b>c.b;} int main () {int X,i=0;while (cin>>x) {i=0;while (cin>>per[i].n>>per[i].b,per[i].n+per[i].b) {i++;} Sort (per,per+i,cmp), int m;for (int j=0;j<i;j++) {if (per[j].n==x) {m=per[j].b;for (int k=0;k<i;k++) if (per[k].b== M) {cout<<k+1<<endl;break;}}} return 0;}
Hangzhou Electric HDU ACM 1718 Rank