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 |
Re:同在3725过了,这里WA 了In Reply To:请教,这代码过了3725却在这WA了,不知道哪的问题 Posted by:200731000623 at 2009-09-18 03:04:36 #include <cstdlib> #include <iostream> using namespace std; long long por(long long x) { long long y=1; for(long long i=0;i<x;i++) y*=10; return y; } int main(int argc, char *argv[]) { long long s; char m[30],k[30]; while(scanf("%s%s",m,k)!=-1) { long long im=0,ik=0,i; long long lm=strlen(m),lk=strlen(k); if(m[0]=='1') { for(i=1;i<lm;i++) if(m[i]!='0') break; if(i==lm) { if(k[0]==lm+'0') printf("%I64d\n",por(lm-1)); else printf("0\n"); continue; } } for(i=0;i<lm;i++) im=im*10+m[i]-'0'; for(i=0;i<lk;i++) ik=ik*10+k[i]-'0'; long long s=0,x=0; for(i=0;i<lm;i++) {x=x*10+m[i]-'0';s+=(x-por(i))+1;} if(s>ik) {printf("0\n");continue;} else if(s==ik) {printf("%I64d\n",im);continue;} x=im-por(lm-1); for(i=lm;s<ik;i++) { x*=10; s+=x; } s-=x;x=ik-s-1; printf("%I64d\n",x+por(i-1)); } return EXIT_SUCCESS; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator