这题做了后,不敢再用C++输入输出了,艾玛。。。调C++的runtime error,调了一上午,原来才发现是那个std::ios::sync_with_stdio(false)有问题!!以后再慢慢尝试这个语句把吧
C++:
#include<iostream> #include<algorithm> #include<string> using namespace std; int N,M,G;//人数,考题数,分数线 int rankp[100]; typedef struct node{ string name; int score; }node; node b [1011]; int problem_num; int total_num; bool ccc(node a,node b){ if(a.score!=b.score)return a.score>b.score; else if(a.score==b.score&&b.name>a.name)return true; else return false; } int main(int argc, char *argv[]) { // freopen("1014.in", "r", stdin); string tmp; while(cin>>N){ if(N==0)break; cin>>M>>G; int ans=0; for(int i=1;i<=M;++i) cin>>rankp[i]; for(int i=0;i<N;++i) { cin>>tmp; cin>>total_num; int sum=0; while(total_num--){ cin>>problem_num; sum+=rankp[problem_num]; } if(sum>=G) { b[ans].name=tmp; b[ans++].score=sum; } } sort(b,b+ans,ccc); cout<<ans<<"\n"; for(int i=0;i<ans;++i) { cout<<b[i].name<<" "<<b[i].score<<"\n"; } } return 0; } /************************************************************** Problem: 1014 User: kirchhoff Language: C++ Result: Accepted Time:180 ms Memory:1544 kb ****************************************************************/
#include<stdio.h> #include<string.h> #include<stdlib.h> int N,M,G;//人数,考题数,分数线 int rankp[11]; typedef struct node{ char name[21]; int score; }node; node b [1011]; int problem_num; int total_num; int ccc(void *a,void *b){ node x=*(node*)a; node y=*(node*)b; if(x.score!=y.score)return x.score<y.score; else return strcmp(x.name,y.name); } int main(int argc, char *argv[]) { // freopen("1014.in", "r", stdin); while(~scanf("%d",&N)&&N){ char tmp[21]; if(N==0)break; scanf("%d %d",&M,&G); int ans=0; for(int i=1;i<=M;++i) scanf("%d",&rankp[i]); for(int i=0;i<N;++i) { scanf("%s",tmp); scanf("%d",&total_num); int sum=0; while(total_num--){ scanf("%d",&problem_num); sum+=rankp[problem_num]; } if(sum>=G) { strcpy(b[ans].name,tmp); b[ans++].score=sum; } } qsort(b,ans,sizeof(node),ccc); printf("%d\n",ans); for(int i=0;i<ans;++i) { printf("%s %d\n",b[i].name,b[i].score); } } return 0; } /************************************************************** Problem: 1014 User: kirchhoff Language: C Result: Accepted Time:90 ms Memory:944 kb ****************************************************************/
原文地址:http://blog.csdn.net/wdkirchhoff/article/details/41924191