Thursday, 1 February 2018

Adding Reversed Number (ADDREV) in C++ - SPOJ

Tags

C++ Program for the adding reversed number problem of spoj is given below. The given solution is accepted by spoj judge.


PROGRAM:

#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
int reverse(long long int num){
	  
	    long long int number=0;
	    while(num!=0){

	            long long int rem=num%10;
	            num=num/10;
	            number=number*10+rem;
	    }
	    return number;
}
int main(){
	
	   long long int n;
	   cin>>n;
	   while(n--){
	       string a,b;
           cin>>a>>b;
	       reverse(a.begin(),a.end());
	       reverse(b.begin(),b.end());
	       long long int c=stoi(a)+stoi(b);
	       c=reverse(c);
	       cout<<c<<" <--Output\n\n";

	   }
	   return 0;
}

OUTPUT:


EmoticonEmoticon