AC日记——计算2的N次方 openjudge 1.6 12

12:计算2的N次方

总时间限制: 
1000ms
 
内存限制: 
65536kB
描述

任意给定一个正整数N(N<=100),计算2的n次方的值。

输入
输入一个正整数N。
输出
输出2的N次方的值。
样例输入
5
样例输出
32
提示
高精度计算

 

思路:

  模拟;

 

来,上代码:

#include<cstdio>

using namespace std;

int n;

char s[101];

int main()
{
    s[0]=1;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=99;j++) s[j]=s[j]+s[j];
        for(int j=0;j<=99;j++) if(s[j]>9) s[j+1]+=s[j]/10,s[j]%=10;
    }
    for(int i=99;i>=0;i--)
    {
        if(s[i]==0) continue;
        for(int j=i;j>=0;j--) putchar(s[j]+'0');
        break;
    }
    return 0;
}

 

posted @ 2016-12-04 17:10  IIIIIIIIIU  阅读(1167)  评论(0编辑  收藏  举报