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> 本来是这样的程序,用了15毫秒 int main() { int sum=0,time,i,t,top; char s[11]; scanf("%s",s); for(i=0;i<=9;i++) { if(s[i]>='0'&&s[i]<='9') sum+=(s[i]-'0')*(10-i); else if(s[i]=='X') sum+=10*(10-i); else {time=10-i;t=i;} } if(t==9) top=10;else top=9; t=-1; for(i=0;i<=top;i++) if((sum+i*time)%11==0) {t=i;break;} if(t==10) printf("X\n"); else printf("%d\n",t); return 0; } 换成这样后就没用什么时间了 #include<stdio.h> #include<string.h> int main() { int sum,time,i,t,top; char s[11]; while(scanf("%s",s)==1) { sum=0; for(i=0;i<=9;i++) { if(s[i]>='0'&&s[i]<='9') sum+=(s[i]-'0')*(10-i); else if(s[i]=='X') sum+=10*(10-i); else {time=10-i;t=i;} } if(t==9) top=10;else top=9; t=-1; for(i=0;i<=top;i++) if((sum+i*time)%11==0) {t=i;break;} if(t==10) printf("X\n"); else printf("%d\n",t); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator