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 |
终于ac, 总结下新手呵呵,自我反省。 输入时 没有检查 = EOF, 结果导致 ole。 数据考虑不全面。 借鉴了别人的测试数据改了好久。基本上只要稍微另类点的数据1就有问题。 最严重的时没有仔细思考。想当然的作。最初的代码在计算两个书相乘的时候,把乘数和被乘数都用了数组表示。 这样,日工作量大了nn倍,还各种混乱。 后来查测试数据时也看看别人怎么写的。才发现,把乘数存储在数组中就好了,被乘数直接记成证书就ok的。慢慢成长吧。。。把代码贴贴,ac了,暂时实在懒得再改了,自我留念啦。 #include <stdio.h> int main(void) { char num[7],output[105]; int res[105],tRes[105], power,pPos,tPos,i,j,h,k,fact;//,posHold; int first=0; while (scanf("%s %d", num, &power)!=EOF) { if (!first) first = 1; else { printf("\n"); } fact = 0; for (i=0; i<=5; i++) { if (num[i] != '.') fact = fact*10+num[i] - '0'; else pPos = i; } //posHold = pPos; if (!fact) ; else { for (i=0; i<105; i++) res[i] = 0; for (i=0,j=0; i<=5; i++) { if (num[i] != '.') { res[100+j] = num[i]-'0'; j++; } } tPos = 100; for (i=0; i<power-1; i++) { for (j=0; j<105-tPos; j++) tRes[j] = fact*res[104-j]; for (k=0; k<105; k++) res[k] = 0; for (h=0; h<j; h++) { k=h; while (tRes[h]>0) { res[104-k] += tRes[h]%10; tRes[h] /= 10; k++; } if (105-k < tPos) tPos = 105-k; } } int tt; for (i=104,k=0; i>=tPos; i--) { tt = (res[i]+k)/10; res[i] = (res[i]+k)% 10; k = tt; } h = k; i = tPos-1; while (h>0 && i) { res[i] = h%10; i--; h /=10; } for (i=tPos,h=0; i<105; i++,h++) output[h] = res[i]+'0'; output[h] = '\0'; pPos = (5-pPos)*power; if( h-pPos < 0) { printf("."); int temp = h-pPos; char zero[105]; int t=0; while (temp++<0) zero[t++] = '0'; zero[t] = '\0'; for (i=h-1; output[i] =='0'; i--); if (output[i] == '.') output[i] = '\0'; else output[i+1] = '\0'; /*i=0; while (output[i]=='0') i++; for (h=0; output[i]!='\0'; h++,i++) output[h] = output[i]; output[h] = '\0'; */ printf("%s%s",zero,output); //printf("%s",zero); } else { for (j=h; j>=h-pPos; j--) { output[j+1] = output[j]; } output[j+1] = '.'; h++; for (i=h-1; output[i] =='0'; i--); if (output[i] == '.') output[i] = '\0'; else output[i+1] = '\0'; i=0; while (output[i]=='0') i++; for (h=0; output[i]!='\0'; h++,i++) output[h] = output[i]; output[h] = '\0'; printf("%s",output); } } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator