#include<iostream>
#include<string>
using namespace std;
string add(string s1,string s2){ //大数 s1 + s2
if(s1.length()<s2.length()){
string temp=s1;
s1=s2;
s2=temp;
}
for(int i=s1.length()-1,j=s2.length ()-1;i>=0;i--,j--){
s1[i]=char(s1[i]+( j>=0 ? s2[j]-'0' : 0));
if(s1[i]-'0'>=10) {
s1[i]=char( (s1[i]-'0')%10+'0' );
if(i) s1[i-1]++;
else s1="1"+s1;
}
}
return s1;
}
int main()
{
int t;
cin >> t;
while(t--)
{
string s = "0", temp = "0";
while(cin >> temp, temp != "0")
{
s = add(s, temp);
}
cout << s << endl;
if(t != 0)
cout << endl;
}
return 0;
}
HDU 1047 使用大数模板,轻松AC
最新推荐文章于 2021-02-23 16:17:56 发布