1 #include <iostream> 2 #include <string> 3 #include<algorithm> 4 using namespace std; 5 int main(){ 6 string str1; 7 string str2; 8 while(cin>>str1>>str2){ 9 int size1 = str1.size()-1; 10 int size2 = str2.size()-1; 11 int flag = 0; 12 for(int i=0;i<=size1;i++){ 13 if(!(str1[i]>=‘0‘ && str1[i] <= ‘9‘)){ 14 cout<<"error"<<endl; 15 flag = 1; 16 break; 17 } 18 } 19 if(flag) break; 20 for(int i=0;i<=size2;i++){ 21 if(!(str2[i]>=‘0‘ && str2[i] <= ‘9‘)){ 22 cout<<"error"<<endl; 23 flag = 1; 24 break; 25 } 26 } 27 if(flag) break; 28 string sum; 29 int carry = 0; 30 int j = 0; 31 while(size1>=0 && size2>=0){ 32 int nsum = (str1[size1] - ‘0‘) + (str2[size2] - ‘0‘) + carry; 33 carry = nsum/10; 34 nsum = nsum%10; 35 sum += to_string(nsum); 36 size1--; 37 size2--; 38 } 39 while(size1 >= 0){ 40 int nsum = (str1[size1] - ‘0‘) + carry; 41 carry = nsum/10; 42 nsum = nsum%10; 43 sum += to_string(nsum); 44 size1--; 45 } 46 while(size2 >= 0){ 47 int nsum = (str2[size2] - ‘0‘) + carry; 48 carry = nsum/10; 49 nsum = nsum%10; 50 sum += to_string(nsum); 51 size2--; 52 } 53 if(carry){ 54 sum += ‘1‘; 55 } 56 reverse(sum.begin(),sum.end()); 57 cout<<sum<<endl; 58 } 59 }