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 <stdlib.h> #include <string.h> int main() { int n,i,j,digit,carry,sum,flag; char s[20]; int a[1000]; while(scanf("%s%d",s,&n) != EOF) { memset(a,0,sizeof(a)); int len = strlen(s); int x = len; flag = 0; for (i = 0;i < len;i++) { if (s[i] == '.') { break; } } if (i == len) { len = 0; } else len = len - 1 - i; int d = atoi(s); for (j = i+1;j < x;j++) { d = d * 10 + s[j] - 48; } for (j = i+1;j < x;j++)//判断小数点后面是不是全为0,觉定是否输出. { if (s[j] != '0') { flag = 1; break; } } a[0] = 1; digit = 1; j = 0; for (i = 0;i < n;i++) { carry = 0; for (j = 0;j < digit;j++) { sum = d * a[j] + carry; a[j] = sum % 10; carry = sum / 10; } while(carry) { a[digit++] = carry % 10; carry /= 10; } } for (j = 0;j < digit;j++) { if (a[j] != 0) { break; } } len = len * n; for (i = digit-1;i >= len;i--) { printf("%d",a[i]); } if(len != 0 && flag) printf("."); for (i = len-1;i >= j;i--) { printf("%d",a[i]); } 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