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<stdio.h> #include<string.h> int main() { int scenario; scanf("%d",&scenario); char name[10][10]; int number=0; char Anne[5]="Anne"; char Bob[4]="Bob"; char Karin[6]="Karin"; char Dave[5]="Dave"; char Charly[7]="Charly"; char Edward[7]="Edward"; char Frank[6]="Frank"; while(scenario--) { number++; int cinema=0; int bar=0; int disco=0; char ch=' '; int i=0; int j; int judge_Anne=0; int judge_Bob=0; int judge_Karin=0; int judge_Dave=0; int judge_Charly=0; int judge_Edward=0; int judge_Frank=0; while(ch!='\n') { scanf("%s",name[i++]); ch=getchar(); } for(j=0;j<i;j++) { if(strcmp(name[j],Anne)==0) judge_Anne=1; else if(strcmp(name[j],Bob)==0) judge_Bob=1; else if(strcmp(name[j],Karin)==0) judge_Karin=1; else if(strcmp(name[j],Dave)==0) judge_Dave=1; else if(strcmp(name[j],Charly)==0) judge_Charly=1; else if(strcmp(name[j],Edward)==0) judge_Edward=1; else judge_Frank=1; } if(judge_Anne) { if(judge_Charly) cinema++; cinema++; } if(judge_Bob) { if(judge_Dave&&(!judge_Karin)) bar++; else if(judge_Karin&&(!judge_Edward)&&judge_Anne&&(!judge_Dave)) disco++; else if(judge_Edward&&(!judge_Dave)) bar++; else if(!judge_Anne&&(!judge_Karin)) bar++; else ; } if(judge_Karin) { if(judge_Charly) disco++; else if((!judge_Charly)&&judge_Anne) cinema++; else if(!judge_Charly&&(!judge_Anne)) bar++; } if(judge_Edward) { if(judge_Anne&&(!judge_Charly)) bar++; else cinema++; } if(judge_Frank) { if(judge_Anne) disco++; else if((!judge_Anne)&&(!judge_Bob)) cinema++; } printf("Scenario #%d:\n",number); if(cinema>bar&&cinema>disco) printf("cinema\n"); else if(bar>cinema&&bar>disco) printf("bar\n"); else if(disco>cinema&&disco>bar) printf("disco"); else printf("stay at the Hacienda\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator