Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
各位大牛,请帮我看看哪错了#include <iostream> #include <cstdlib> using namespace std; struct student { int score; char name[31]; }; int compare (const void * a, const void * b) { return ( ((student*)a)->score < ((student *)b)->score); } int main() { int n; cin>>n; char s[31]; int i,j; char ch=getchar(); for(i=0;i<n;++i) gets(s); int test; cin>>test; while(test--) { int target; student str[10001]; for(i=0;i<n;++i) { cin>>str[i].score; char c=getchar(); gets(str[i].name); if(strcmp(str[i].name,"Li Ming")==0) target=str[i].score; } qsort (str, n, sizeof(student), compare); for(i=0;i<n;++i) if(str[i].score==target && strcmp(str[i].name,"Li Ming")==0) j=i; i=j; while(i>=0) { int t=i-1; if(t<0) { cout<<1<<endl; break; } if(str[i].score==str[t].score) --i; else { cout<<i+1<<endl; break; } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator