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 |
无语了,WA了N次,不知道什么原因,测试很多情况都过了啊大牛们,帮帮忙,测试了很多数据都没有问题,不知道为什么WA,还有就是用G++时编译出错,也不知道什么原因,用C++就WA 代码如下: #include <iostream> #include <cstdio> using namespace std; __int64 s[20] = {0,9, 18, 108, 198, 1098, 1998, 10998, 19998, 109998, 199998, 1099998, 1999998, 10999998, 19999998, 109999998, 199999998, 1099999998, 1999999998, 10999999998 }; void inttochar (char a[], __int64 x) { int i,t; for (i = 0; ; i++) { t = x % 10; a[i] = t + '0'; x = x / 10; if (x == 0) break; } a[i + 1] = '\0'; } int main () { // freopen ("2402.txt","r",stdin); __int64 k,t,tmp; int i,j,r,mid; char a[22]; while (1) { scanf ("%I64d",&k); if (k == 0) break; for (i = 1; ; i++) if (k < s[i]) break; if (i == 1) printf ("%I64d\n",k); else { t = k - s[i - 1]; if (t == 0) { for (j = 0; j < i - 1; j++) printf ("9"); printf ("\n"); } else { if (i % 2 == 0) { r = i / 2; switch (r) { case 1: printf ("%I64d",t); printf ("%I64d",t); break; case 2: printf ("%I64d",t + 9); inttochar (a,t + 9); printf ("%s",a); break; case 3: printf ("%I64d",t + 99); inttochar (a,t + 99); printf ("%s",a); break; case 4: printf ("%I64d",t + 999); inttochar (a,t + 999); printf ("%s",a); break; case 5: printf ("%I64d",t + 9999); inttochar (a,t + 9999); printf ("%s",a); break; case 6: printf ("%I64d",t + 99999); inttochar (a,t + 99999); printf ("%s",a); break; case 7: printf ("%I64d",t + 999999); inttochar (a,t + 999999); printf ("%s",a); break; case 8: printf ("%I64d",t + 9999999); inttochar (a,t + 9999999); printf ("%s",a); break; case 9: printf ("%I64d",t + 99999999); inttochar (a,t + 99999999); printf ("%s",a); break; case 10: printf ("%I64d",t + 999999999); inttochar (a,t + 999999999); printf ("%s",a); break; } printf ("\n"); } else { r = i / 2; mid = (t - 1) % 10; tmp = (t - 1) / 10 + 1; switch (r) { case 1: printf ("%I64d",tmp); printf ("%d",mid); printf ("%I64d",tmp); break; case 2: printf ("%I64d",tmp + 9); printf ("%d",mid); inttochar (a,tmp + 9); printf ("%s",a); break; case 3: printf ("%I64d",tmp + 99); printf ("%d",mid); inttochar (a,tmp + 99); printf ("%s",a); break; case 4: printf ("%I64d",tmp + 999); printf ("%d",mid); inttochar (a,tmp + 999); printf ("%s",a); break; case 5: printf ("%I64d",tmp + 9999); printf ("%d",mid); inttochar (a,tmp + 9999); printf ("%s",a); break; case 6: printf ("%I64d",tmp + 99999); printf ("%d",mid); inttochar (a,99999); printf ("%s",a); break; case 7: printf ("%I64d",tmp + 999999); printf ("%d",mid); inttochar (a,tmp + 999999); printf ("%s",a); break; case 8: printf ("%I64d",tmp + 9999999); printf ("%d",mid); inttochar (a,tmp + 9999999); printf ("%s",a); break; case 9: printf ("%I64d",tmp + 99999999); printf ("%d",mid); inttochar (a,tmp + 99999999); printf ("%s",a); break; case 10: printf ("%I64d",tmp + 999999999); printf ("%d",mid); inttochar (a,tmp + 999999999); printf ("%s",a); break; } printf ("\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