[c]代码库
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXN 1000
int ans[MAXN], result[MAXN], Baselen;
int Mul(int base[], int len);
int main()
{
int i, j;
int n = 0, pos, c, len, count, base[6];
char R[6];
memset(R, '0', sizeof(R));
memset(result, 0, sizeof(result));
memset(base, 0, sizeof(base));
while (scanf("%s%d", R, &n)==2)
{
Baselen = strlen(R);
pos = 0;
c = 0;
len = 0;
count = 0;
memset(result, 0, sizeof(result));
for (i=Baselen-1; i>=0; i--)
{
if (R[i]) break;
}
Baselen = i;
for (i=0; i<Baselen+1; i++)
{
if (R[i] != '.') result[c++] = R[i]-'0';
else pos = Baselen-i;
}
memcpy(base, result, sizeof(base));
len = Baselen;
for (i=1; i<n; i++)
{
if (n==1) break;
len = Mul(base, len);
}
pos = n*pos;
i = 0;
while (result[i]==0&&i<len-pos) i++;
count = i;
for (i=MAXN-1; i>=0; i--) if (result[i]) break;
j = i;
for (i=count; i<=j; i++)
{
if (i ==len-pos) printf(".");
printf("%d", result[i]);
}
printf("\n");
}
return 0;
}
int Mul(int base[], int len)
{
memset(ans, 0, sizeof(ans));
int c = 0, k = 0;
int i, j;
for (i=Baselen-1; i>=0; i--)
{
for (j=len-1, c=Baselen-1-i; j>=0; j--)
{
ans[c++] += base[i]*result[j];
}
}
for (i=0; i<MAXN-1; i++)
{
ans[i+1] += ans[i]/10;
ans[i] %= 10;
}
for (i=MAXN-1; i>=0; i--)
{
if (ans[i]||i == c) break;
}
for ( ; i>=0; i--)result[k++] = ans[i];
return c+1;
}