HDU 1063 Exponentiation

跟POJ 1001 一样的题。不过数据很奇葩就是了。


用POJ AC的程序提交过不了,于是重写了。


注意:

001200 0 =1

001200 1 =1200

0.0000 2 =0

00000  1 =0

0000.  1 =0


反正各种能想到的都试试就知道了。


#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<cmath>


#define INF 0x7fffffff
#define eps 1e-6
#define LL long long

#define CLRi for(int i=0;i<n;i++)
#define CLRj for(int j=0;j<n;j++)
#define CLRk for(int k=0;k<n;k++)

#define debug puts("==fuck==");

#define acfun std::ios::sync_with_stdio(false)
#define Nmax 1001
#define Mmax 1001*1001

using namespace std;


void powfff(char *str,int n)
{
    if(n==0)
    {
        printf("1\n");
        return ;
    }
    queue<int>q;n--;
    bool point=0;
    int len=strlen(str);
    int site=0;
    for(int i=len-1;i>=0;i--)
    {
        if(str[i]=='.')
        {
            point=1;break;
        }
    }
    if(point)
    {
        for(len--;str[len]=='0';len--);
        for(int i=len;str[i]!='.';i--)
            site++;
        for(int i=len;i>=0;i--)
            if(str[i]!='.')q.push(str[i]-'0');
    }
    else
    {
        int tmp=atoi(str);
        while(tmp)
        {
            q.push(tmp%10);
            tmp/=10;
        }
        len--;
    }
    int base=0;
    for(int i=0;i<=len;i++)
    {
        if(str[i]=='.')continue;
        base=base*10+str[i]-'0';
    }
//    printf("base:%d\n",base);
    site*=(n+1);
    while(n--)
    {
        int h=q.size();
        int e=0;
        int c=0,s;
        while(e!=h)
        {
            s=q.front()*base+c;
            e++;q.pop();
            c=s/10;
            q.push(s%10);
        }
        while(c)
        {
            q.push(c%10);
            c/=10;
        }
    }
    stack<char>out;
    while(!q.empty())
    {
        int tmp=q.front();q.pop();
        site--;
        out.push(tmp+'0');
        if(site==0)
            out.push('.');
    }
    while(site>0)
    {
        site--;
        out.push('0');
        if(site==0)
            out.push('.');
    }
    while(!out.empty())
    {
        char ch=out.top();
        if(ch=='0')
        {
            out.pop();
            continue;
        }
        else break;
    }
    if(!out.empty())
    {
        while(!out.empty())
        {
            printf("%c",out.top());out.pop();
        }
    }
    else
        printf("0");
    printf("\n");
}
int main()
{
    char str[21];
    int n;
    while(~scanf("%s%d",str,&n))
    powfff(str,n);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值