2009-08-19 22:25:53來源不明

ACM 748 Q748: Exponentiation

作法 : BIGNUMBER

請注意小數點的位置與是否要輸出小數點

/**********************************************************/

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
 int n;
 char s[100];
 while(scanf("%s %d",s,&n)==2)
     {
        int m=strlen(s),a,b,c,R[100]={0},poi=0,top=0;
        for(a=0,b=m-1;b>=0;a++,b--)
           {
              if(s[b]=='.')
                    poi=a;
              else
                    R[top++]=s[b]-48;
           }
        poi=poi*n;
        int ans[130]={0};
        ans[0]=1;
        for(a=0;a<n;a++)
           {
             int temp[130]={0};
             for(b=0;b<m;b++)
                for(c=0;c<130;c++)
                   {
                     temp[b+c]+=(ans[c]*R[b]);
                     temp[b+c+1]+=(temp[b+c]/10);
                     temp[b+c]%=10;
                   } 
             for(b=0;b<130;b++)
                ans[b]=temp[b];
           }
        int down=poi;
        for(a=0;a<poi;a++)
          {
          if(ans[a]!=0)
            {down=a;break;}
          } 
        for(a=129;a>=poi;a--)
           if(ans[a]!=0)
              {
                for(;a>=poi;a--)
                   printf("%d",ans[a]);
                break;
              }
                if(down<poi)
                  {
                   printf(".");    
                   for(;a>=down;a--)
                     printf("%d",ans[a]);
                  }  
        printf("\n");
     }
 return 0;
}