提交时间:2023-10-11 14:03:48

运行 ID: 106419

#include<bits/stdc++.h> using namespace std; string adds(string s1,string s2) { int lena=s1.length(),lenb=s2.length(),a[200]={},b[200]={},c[200]={},lenc=1,x=0,i; string answer; for(i=0;i<=lena-1;i++) a[lena-i]=s1[i]-'0'; for(i=0;i<=lenb-1;i++) b[lenb-i]=s2[i]-'0'; while(lenc<=lena||lenc<=lenb) { c[lenc]=a[lenc]+b[lenc]+x; x=c[lenc]/10; c[lenc]%=10; lenc++; }c[lenc]=x; if(c[lenc]==0){lenc--;} for(i=lenc;i>=1;i--){answer+=c[i]+'0';} return answer; } struct number { string a; }num[114514]; string ans; int n; int main() { cin>>n; for(long long i=0;i<n;i++) {cin>>num[i].a;} for(long long i=0;i<n;i++) { for(long long j=i+1;j<n;j++) {ans=adds(ans,adds(num[i].a,num[j].a));} } cout<<ans; return 0; }