#include <cstdio> #include <algorithm> #include <string> using namespace std; struct cc { int id; int mark; }a[10000]; bool cmp(cc a,cc b) {return (a.mark>b.mark);} int main() { int m,n; while(scanf("%d",&n)!=EOF) { int i=0; while(scanf("%d%d",&a[i].id,&a[i].mark),a[i].id!=0) i++; int s=i; sort(a,a+s,cmp); for (i=0; i<s; i++) if (a[i].id==n) break; while ((i>1)&&(a[i].mark==a[i-1].mark)) i--; printf("%d ",i+1); } return 0; }
注意点:去重,还有切记判断是双等号!