| ||||||||||
| 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,例子中的测试数据和帖子中提到的数据都正确啊#include <stdio.h>
#include <math.h>
struct T {
int a[125];
int l, last;
struct T *next;
};
int main(int argc, char **argv)
{
struct T *t, *tmp;
double f;
int n, i, j, num;
struct T *start = NULL;
while (scanf("%lf %d", &f, &n) == 2) {
if (f<=0 || f>=99.999 || n<=0 || n>25)
return 1;
tmp = malloc(sizeof(struct T));
tmp->next = NULL;
if(start ==NULL)
start = tmp;
if (t == NULL)
t = tmp;
else {
t->next = tmp;
t = t->next;
}
for (i=0; i<125; i++) {
t->a[i] = 0;
}
if (f > 9.9999) {
f = f*1000;
t->l = 3*n;
} else {
f = f*10000;
t->l = 4*n;
}
num = round(f);
int temp = num;
for (i=0; i<5; i++)
{
t->a[i] = temp%10;
temp = temp/10;
}
for(j = 0; j < n-1; j++) {
int c = 0;
for (i=0; i<125; i++)
{
t->a[i] = t->a[i]*num + c;
c = t->a[i]/10;
t->a[i] = t->a[i]%10;
}
}
}
for (t = start; t != NULL; t = t->next) {
t->last = 0;
while (t->a[t->last] == 0)
t->last++;
i = 124;
while (t->a[i] == 0)
i--;
if (i < t->l)
i = t->l-1;
if(t->last > t->l)
t->last = t->l;
for (i; i >= t->last; i--) {
if (i == t->l-1)
printf(".");
printf("%d", t->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