BigNumSum

You will be given two numbers of 40 digits each. You will have to print the summation of these two n…

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

What’s the problem?


#include<set>
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<climits>
#include<cstring>
#include<cmath>
#include<unordered_map>
#include<sstream>
#include<cmath>
#include<iomanip>
#include<numeric>
using namespace std;

int main(){
	string a,b;
	cin>>a>>b;
	vector<int> v1;
	vector<int> v2;
	for(int i=0;i<a.size();i++){
		v1.push_back(a[i]-'0');
		v2.push_back(b[i]-'0');
	}
	int s=0;
	string res="";
	for(int i=v1.size()-1;i>=0;i--){
		int sum=v1[i]+v2[i]+s;
		if(sum>=10){
			string r=to_string(sum);
			res+=r[1];
			s=r[0]-'0';
		}
		else{
			string x=to_string(sum);
			res+=x;
			s=0;
		}
	}
	reverse(res.begin(),res.end());
	cout<<res;
}

Bro, test it for 98 + 102 ( not 102 + 98).

I have got AC before bro…by the way thanks for responding :slight_smile:

Java donot use Bigint