zoukankan      html  css  js  c++  java
  • poj 1001 Exponentiation

     1 #include<stdio.h>
     2 #include<string.h>
     3 
     4 int n, p, len, flag;
     5 char a[10],s[10], sum[200], sum2[200];
     6 
     7 void solve()
     8 {
     9     memset(sum2,0,sizeof(sum2));
    10     len += 5;
    11     for(int i = 0; i < p; i ++)
    12     {
    13         int c = 0;
    14         for(int j = 0; j <= len; j ++)
    15         {
    16             sum2[i+j] += s[i]*sum[j] + c;
    17             c = sum2[i+j]/10;
    18             sum2[i+j] = sum2[i+j]%10;
    19         }
    20     }
    21     for(int i = 0; i <= len+5; i ++)
    22         sum[i] = sum2[i];
    23     //for(int i = 0; i <= len+5; i ++)
    24     //    printf("%d ",sum[i]);
    25     //puts("");
    26     //getchar();getchar();
    27 }
    28 
    29 int main()
    30 {
    31     while(~scanf("%s%d",&a, &n))
    32     {
    33         memset(sum, 0, sizeof(sum));
    34         p = 0;
    35         for(int i = 5; i >= 0; i --)
    36             if(a[i] != '.') 
    37             {
    38                 sum[p] = a[i]-'0';
    39                 s[p++] = a[i]-'0';
    40             }
    41             else flag = i;
    42         len = 0;
    43         for(int i = 0; i < n-1; i ++)
    44             solve();
    45         int i, j;
    46         for(i = n*5; i >=0; i --)
    47             if(sum[i] != 0 || i == n*(5-flag)) break;
    48         
    49         for(j = 0; j <= n*5; j ++)
    50             if(sum[j] != 0 || j == n*(5-flag) )break;//printf("i=%d j=%d\n",i,j);
    51         //printf("sum[49]=%d\n",sum[49]);
    52         for(int k = i; k >= j; k --)
    53         {
    54             if(k == i && i == n*(5-flag))
    55             {
    56                 if(sum[k] != 0) printf("%d",sum[k]);
    57                 if(n*(5-flag) != j)printf(".");
    58             }
    59             else
    60             {
    61                 printf("%d",sum[k]);
    62                 if(k == j && j == n*(5-flag));
    63                 else if(k == n*(5-flag)) printf(".");
    64             }    
    65         }
    66         puts("");
    67     }
    68     return 0;
    69 }
  • 相关阅读:
    python快速入门及进阶
    Git基础及进阶-系统总结
    go语言快速入门教程
    go学习笔记
    win10中,vscode安装go插件排雷指南
    centos7下安装pcre库(pcretest)
    c语言typedef
    虚拟机中安装centos7后无法上网,使用桥接网络+ssh
    强化学习-Q-learning学习笔记
    python基础教程系列1-基础语法
  • 原文地址:https://www.cnblogs.com/yuzhaoxin/p/2668443.html
Copyright © 2011-2022 走看看