uva748 Exponentiation

我花了将近三个小时AC了这道题,其中的艰辛这张图片就能体现出来,我都觉得今天我是不是就完不成这道题目了,真是费劲,找了半天错误,最后才知道,我刚开始代码没有错误,至少算法没有错误,只是没有看见如果结果<0 的话,前面是不能输出0的

View Code
#include<stdio.h>
#include<string.h>
int main()
{
    int m, i, j, temp, top, t, len;
    char st[9];
    while(scanf("%s%d",st,&m) != EOF)
    {
        long long factor[10] = {0}, num[500] = {0}, flag = 0;
        i = j = temp = top  = t = len = 0;
        len = strlen(st);
        i = 0;
        while(st[i] == '0' && i < len)
            i++;
        for(j = 0;i < len; i++)
        {
            if(st[i] != '.')
                factor[j++] = st[i]-'0';
            else
                t = len-i-1;
        }
        t *= m;
        flag = 0;
        temp = 1;
        for(i = j-1;i > -1; i--)
        {
            flag += temp*factor[i];
            temp *= 10;
        }
        temp = top = j;
        for(i = 0;i < j; i++)
            num[i] = factor[j-1-i];
        m--;
        while(m--)
        {
            for(i  = 0;i < top; i++)
            {
                num[i] *= flag;
            }
            i = 0;
            while(1)
            {
                if((num[i] == 0) && (i > top))
                    break;
                num[i+1] += num[i]/10;
                num[i] %= 10;
                i++;
            }
            top = i;
        }
        t--;
        if(top <= t)
        {
            i = 0;
            while(num[i] == 0)
                i++;
            printf(".");
            while(t >= i)
            {
                printf("%lld",num[t--]);
            }
        }
        else
        {
            top--;
            i = 0;
            while(num[i] == 0)
            {
                i++;
            }
            while(top >= i)
            {
                printf("%lld",num[top--]);
                if(top == t)
                {
                    printf(".");
                }
            }
        }
            printf("\n");
    }
    return 0;
}

但是当我找到

原文地址:https://www.cnblogs.com/SDUTYST/p/2531936.html