语法错误
查看原帖
语法错误
716488
a_study_xxs楼主2023/3/20 21:51
#include<iostream>
#include<cstring>
using namespace std;
string f[100005] ;
int a[400], b[400], c[400];
string cheng(string s1,string s2){
	memset(a , 0 , sizeof(a)) ;
	memset(b , 0 , sizeof(b)) ;
	memset(c , 0 , sizeof(c)) ;
	int lena = 0 ;
	for(int i=s1.size() -1 ; i >= 0 ; i -- ){
		a[lena++] = s1[i] - '0';
	}
	int lenb = 0;
	for(int i=s2.size() -1 ; i >= 0 ; i -- ){
		b[lenb++] = s2[i] - '0';
	}
	int lenc = max(lena ,lenb);
	for(int i = 0 ; i < lenb ; i ++ ){
		for(int j = 0 ; j <= lena ; j ++ ){
			c[i + j] = a[j] * b[i] + c[i + j];
			c[i + j + 1] = c[i + j] / 10;
			c[i + j] %= 10;
		}
	}
	lenc = lena + lenb - 1;
	if(c[lenc] != 0){
		lenc++;
	} 
	string res = "";
	for(int i = lenc-1; i>=0; i--) {
		res += to_string(c[i]);
	}
    return res;
}
string jia(string s1,string s2){
	memset(a , 0 , sizeof(a)) ;
	memset(b , 0 , sizeof(b)) ;
	memset(c , 0 , sizeof(c)) ;
	int lena = 0 ;
	for(int i=s1.size() -1 ; i >= 0 ; i -- ){
		a[lena++] = s1[i] - '0';
	}
	int lenb = 0;
	for(int i=s2.size() -1 ; i >= 0 ; i -- ){
		b[lenb++] = s2[i] - '0';
	}
	int lenc = max(lena ,lenb);
	for(int i = 0 ; i < lenc ; i ++ ){
		c[i] = a[i] + b[i] + c[i];
		c[i+1] = c[i]/10;
		c[i] %= 10;
	}
	if(c[lenc] > 0){
		lenc++;
	} 
	string res = "";
	for(int i = lenc-1; i>=0; i--) {
		res += to_string(c[i]);
	}
    return res;
}
int main(){
	int n ;
	cin >> n ;
	f[1] = "2";
	for(int i = 2 ; i <= n ; i ++ ){
		f[i] = jia( cheng( "2"  , f[i - 1]) , "2") ;
	}
	cout << f[n] ;
	return 0;
}
2023/3/20 21:51
加载中...