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 |
为什么一直wrong time error啊?#include <stdio.h> #include <string.h> #include <stdlib.h> #define N 100000000 long long a[100]; int main() { int i, j, dot, flagdot, n, adv,len, flen; long long k; char s[10],substr[20], str[2000]; while(scanf("%s%ld",s,&n)!=EOF) { memset(a, 0, sizeof(a)); flagdot = 0; dot = -1; k = 0; j = strlen(s) - 1; while(s[j] == '0') j--; for(i = 0; i <= j; i++) { if(s[i] != '.') k = k * 10 + s[i] - '0'; else flagdot = 1; if(flagdot == 1) dot++; } a[0] = k; adv = 0; for( i = 0; i < n - 1; i++) { for(j = 0; j < 99; j++) { a[j] = a[j] * k + adv; adv = a[j] / N; a[j] = a[j] % N; } } i = 99; while(a[i] == 0) i--; itoa(a[i], substr, 10); str[0] = '\0'; strcat(str,substr); i--; while(i >= 0) { itoa((int)a[i],substr, 10); len = 8 - strlen(substr); while(len--) strcat(str,"0"); strcat(str,substr); i--; } len = strlen(str); flen = len - dot * n; if(flen < 0) { putchar('.'); while(flen) { putchar('0'); flen++; } printf("%s\n",str); continue; } else if(flen == len + n || flen == len) { printf("%s\n",str); continue; } for(i = 0; i < flen; i++) putchar(str[i]); putchar('.'); for(i = flen; str[i]; i++) putchar(str[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