HDU 6433 Problem H. Pow

题目传送门
java:

import java.math.BigInteger;
import java.util.*;

public class Main {

    public static void main(String args[]){

        Scanner cin = new Scanner(System.in);
        int T = cin.nextInt();
        BigInteger mul;
        BigInteger two = new BigInteger("2");
        while((T--)!=0){

            int n = cin.nextInt();
            mul = new BigInteger("1");
            for(int i=1;i<=n;i++) mul=mul.multiply(two);
            System.out.println(mul);
        }
    }
}

c++:

#include
using namespace std;

const int maxn=1000000+100;

int bit[maxn];

int main(){
	
	int T;
	scanf("%d",&T);
	while(T--){
		
		int n;
		scanf("%d",&n);
		int len=0;
		bit[0]=1;
	    for(int i=1;i<=n;i++){
	    	
	    	int Add=0;
	    	for(int j=0;j<=len;j++){
	    		
	    		bit[j]=bit[j]*2+Add;
	    		Add=0;
	    		if(bit[j]>=10) bit[j]-=10,Add++;
			}
			if(Add) len++,bit[len]=1; 
		}
		for(int i=len;i>=0;i--) printf("%d",bit[i]),bit[i]=0;
		printf("\n");
	}
} 

你可能感兴趣的:(HDU,ACM)