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 n,num=0; scanf("%d",&n); while(n--) { char a[10]; int sum=0,p; int i,j; scanf("%s",&a); num++; for(i=1;i<=strlen(a);i++) { if(a[strlen(a)-i]=='?') {j=i;continue;} if(i%3==1) sum+=(a[strlen(a)-i]-'0')*9; else if(i%3==2) sum+=(a[strlen(a)-i]-'0')*3; else if(i%3==0) sum+=(a[strlen(a)-i]-'0')*7; } p=sum; for(i=0;i<=9;i++) { sum=p; if(j%3==1) { sum+=9*i; if(sum%10==0) break; } else if(j%3==2) { sum+=3*i; if(sum%10==0) break; } else if(j%3==0) { sum+=7*i; if(sum%10==0) break; } } a[strlen(a)-j]=i+'0'; printf("Scenario #%d:\n",num); printf("%s\n\n",a); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator