Time Limit: 500MS | Memory Limit: 10000K | |
Total Submissions: 149182 | Accepted: 36419 |
Description
This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.
Input
Output
Sample Input
95.123 12 0.4321 20 5.1234 15 6.7592 9 98.999 10 1.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721 .00000005148554641076956121994511276767154838481760200726351203835429763013462401 43992025569.928573701266488041146654993318703707511666295476720493953024 29448126.764121021618164430206909037173276672 90429072743629540498.107596019456651774561044010001 1.126825030131969720661201
Hint
s is a string and n is an integer
C++ while(cin>>s>>n) { ... } c while(scanf("%s%d",s,&n)==2) //to see if the scanf read in as many items as you want /*while(scanf(%s%d",s,&n)!=EOF) //this also work */ { ... }
Source
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
int n,j,t,flag,i1,flag1;
char k[6];
int a[1000];
char b[1001];
int i,y;
while(scanf("%s%d",&k,&n)!=EOF)
{
t=0;
memset(a,0,sizeof(a));
for(i=0;i<6;i++)
{
if(k[i]=='.') break;
}
flag1=i;
flag=flag1;
j=0;
if(flag1<5)
{
j=0;
for(i=0;i<6;i++)
{
if(5-i!=flag)
a[j++]=k[5-i]-'0';
}
for(i=0;i<5;i++)
t+=a[i]*pow(10,i);
for(i=2;i<=n;i++)
{
y=0;
for(j=0;j<1000;j++)
{
i1=a[j]*t+y;
y=i1/10;
a[j]=i1%10;
}
}
flag=5-flag;
flag=flag*n;
j=0;
for(i=0;i<1000;i++)
{
if(i!=flag)
b[i]=a[j++]+'0';
b[flag]='.';
}
for(i=999;i>=0;i--)
{
if(b[i]!='0'||b[i]=='.')
break;
}
for(i1=0;i1<=flag;i1++)
{
if(b[i1]!='0'&&b[i1]!='.')
break;
}
for(j=i;j>=i1;j--)
printf("%c",b[j]);
printf("\n");
}
if(flag1>=5)
{
for(i=0;i<6;i++)
a[i]=k[5-i]-'0';
for(i=0;i<6;i++)
t+=a[i]*pow(10,i);
for(i=2;i<=n;i++)
{
y=0;
for(j=0;j<1000;j++)
{
i1=a[j]*t+y;
y=i1/10;
a[j]=i1%10;
}
}
for(i=0;i<1000;i++)
{
b[i]=a[i]+'0';
}
for(i=999;i>=0;i--)
{
if(b[i]!='0')
break;
}
for(j=i;j>=0;j--)
printf("%c",b[j]);
printf("\n");
}
}
}