提交时间:2023-10-11 13:14:53

运行 ID: 106334

#include<iostream> #include<cstring> using namespace std; int main() { int u,v,w,x,c[5001]={0},len3,len2=1,len1; cin>>u; for(v=1;v<=u;v++) { int a1[5001]={0}; char a[5001]; cin>>a; len1=strlen(a); for(int i=1;i<=len1;i++) a1[i]=a[len1-i]-'0'; x=0; len3=1; while(len3<=len1+1&&len3<=len2) { c[len3]+=a1[len3]+x; x=c[len3]/10; c[len3]%=10; len2++; len3++; } c[len3]=x; } x=0; for(int i=1;i<=len2+1;i++) { c[i]=c[i]*3+x; x=0; x+=c[i]/10; c[i]%=10; } while(c[len2]==0&&len2>1) len2--; for(int i=len2;i>=1;i--) cout<<c[i]; return 0; }