code
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int main(){
ios::sync_with_stdio(false);
char s1[105],s2[105];//store input string
//int a1 ,a2 and dec b1 ,b2;ans c1,c2
static int a1[101],a2[101],b1[101],b2[101],c1[505],c2[505];
int i,flag=1,top_a1,top_a2,top_b1,top_b2,len_c1,len_c2;
int int_carry,dec_carry;
top_a1=top_a2=top_b1=top_b2=0;
len_c1=len_c2=0;
int_carry=dec_carry=0;
cin>>s1>>s2;
for(i=0;i<strlen(s1);++i){
if('.'==s1[i]){
flag=0;
continue;
}
if(flag){
a1[top_a1++]=(s1[i]-'0');
}else{
a2[top_a2++]=(s1[i]-'0');
}
}
int len_a1=top_a1-1;
int len_a2=top_a2-1;
flag=1;
for(i=0;i<strlen(s2);++i){
if('.'==s2[i]){
flag=0;
continue;
}
if(flag){
b1[top_b1++]=(s2[i]-'0');
}else{
b2[top_b2++]=(s2[i]-'0');
}
}
int len_b1=top_b1-1;
int len_b2=top_b2-1;
while(len_a2>=0&&len_a2>len_b2){
c2[len_c2++]=a2[len_a2];
len_a2--;
}
while(len_b2>=0&&len_a2<len_b2){
c2[len_c2++]=b2[len_b2];
len_b2--;
}
while(len_a2>=0&&len_a2==len_b2){
c2[len_c2]=a2[len_a2]+b2[len_b2]+dec_carry;
dec_carry=c2[len_c2]/10;
c2[len_c2]=c2[len_c2]%10;
++len_c2;
--len_a2;
--len_b2;
}
--len_c2;
int_carry+=dec_carry;
while(len_a1>=0&&len_b1>=0){
c1[len_c1]=a1[len_a1]+b1[len_b1]+int_carry;
int_carry=c1[len_c1]/10;
c1[len_c1]=c1[len_c1]%10;
len_c1++;
len_b1--;
len_a1--;
}
while(len_a1>=0){
c1[len_c1]=a1[len_a1]+int_carry;
int_carry=c1[len_c1]/10;
c1[len_c1]=c1[len_c1]%10;
++len_c1;
--len_a1;
}
while(len_b1>=0){
c1[len_c1]=b1[len_b1]+int_carry;
int_carry=c1[len_c1]/10;
c1[len_c1]=c1[len_c1]%10;
++len_c1;
--len_b1;
}
while(int_carry){
c1[len_c1]=int_carry%10;
int_carry/=10;
len_c1++;
}
--len_c1;
for(i=len_c1;i>=0;--i){
cout<<c1[i];
}
if(len_c2>=0){
cout<<'.';
}
for(i=len_c2;i>=0;--i){
cout<<c2[i];
}
cout<<'\n';
return 0;
}
https://blog.dotcpp.com/a/61102