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 |
进10000名了,纪念下,附思路清晰的简短代码,大牛请忽略就好#include <iostream> using namespace std; int main() { char is[15]; scanf("%s",is); int sum=0,index=0; for(int i=9;i>=0;i--){ if(is[i]=='X'){//不能写is[9] sum+=10; continue; }if(is[i]=='?'){ index=i; continue; } sum+=((is[i]-48)*(10-i)); } int n=(index==9)?10:9; int tmp=0,ans=-1; for(int i=0;i<=n;i++){ tmp=sum+i*(10-index); if(tmp%11==0){ ans=i; break; } } if(ans==10)puts("X"); else printf("%d\n",ans); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator