Time Limit: 500MS | Memory Limit: 10000K | |
Total Submissions: 141055 | Accepted: 34473 |
Description
This problem requires that you write a program to compute the exact value of R n 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.1075960194566
Accepted 140K 47MS C++ 4022B 2015-02-06 22:23:01
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#define BASELEN 6
#define EXPLIMIT 25
#define RESULTLEN ((BASELEN - 1)*EXPLIMIT)
#define BITDIF (RESULTLEN-BASELEN)
int ftod(char *,int *);
void PreciseMultiply(int *,int,int*);
void Overflow(int *i_register, int k);
void dtof(int*,int,char*);
void FormatPrintPreciseValue(char*);
int main(void)
{
char c_base[BASELEN] = { 0 };
int exp = 0;
while (scanf("%s %d", c_base, &exp) == 2)
{
int i_base[BASELEN] = { 0 };
int DotPosition = 0;
int i_result[RESULTLEN] = { 0 };
char c_result[RESULTLEN] = { 0 };
DotPosition=ftod(c_base,i_base);
PreciseMultiply(i_base,exp,i_result);
DotPosition = DotPosition*exp;
dtof(i_result,DotPosition,c_result);
FormatPrintPreciseValue(c_result);
}
}
int ftod(char *c_base, int *i_base)
{
int DotPos = 0;
for (int i = 0; i < BASELEN; i++)
{
if (c_base[i]=='.')
{
DotPos =i;
}
i_base[i] = c_base[i] - '0';
}
for (int j = DotPos; j >0 ; j--)
{
i_base[j] = i_base[j - 1];
}
i_base[0] = 0;
DotPos = 5 - DotPos;
return DotPos;
}
void PreciseMultiply(int *i_base, int exp, int i_result[RESULTLEN])
{
for (int i = 0; i < BASELEN; i++)
{
i_result[i+BITDIF] = i_base[i];
}
while (exp>1)
{
int i_register[RESULTLEN] = { 0 };
for (int j = 1; j <= 6;j++)
{
for (int k = 1; k<RESULTLEN; k++)
{
int tmp = i_base[BASELEN-j] * i_result[RESULTLEN-k];
i_register[RESULTLEN-k-j+1] += tmp % 10;
i_register[RESULTLEN-k-j] += tmp / 10;
Overflow(i_register, k);
}
}
for (int l = 0; l < RESULTLEN; l++)
{
i_result[l] = i_register[l];
}
exp--;
}
}
void Overflow(int *i_register,int k)
{
for (int i = k; i >0; i--)
{
int tmp = i_register[i];
i_register[i] = tmp % 10;
i_register[i - 1] += tmp / 10;
}
}
void dtof(int *i_result, int DotPosition, char *c_result)
{
DotPosition = RESULTLEN - 1 - DotPosition;
for (int i = 0; i < DotPosition; i++)
{
i_result[i] = i_result[i + 1];
}
for (int i = 0; i < RESULTLEN; i++)
{
c_result[i] = i_result[i]+'0';
}
c_result[DotPosition] = '.';
}
void FormatPrintPreciseValue(char *c_result)
{
int headzeromark = 0;
int trailingzeromark = RESULTLEN-1;
for (int i = 0; i < RESULTLEN; i++)
{
if (c_result[i]=='0'&&c_result[i+1]=='0')
{
headzeromark ++;
}
else
{
headzeromark++;
// if (c_result[i+1] == '.')
{
// headzeromark--;
}
break;
}
}
for (int j = RESULTLEN-1; j > 0; j--)
{
if (c_result[j]=='0'&&c_result[j-1]=='0')
{
trailingzeromark--;
}
else
{
if (c_result[j]=='0')
{
trailingzeromark--;
}
if (c_result[j-1]=='.')
{
trailingzeromark--;
}
break;
}
}
for (int k = headzeromark; k<=trailingzeromark ; k++)
{
printf("%c", c_result[k]);
}
printf("\n");
}