跟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);
}