Hello,
I'm using C++ for the problem : http://www.spoj.com/problems/ADDREV/
I have tried the test cases given in the problem and some more.
I want to know if i have missed an exception.
#include<iostream>
#include<string>
#include<stdlib.h>
#include<sstream>
using std::cin;
using std::cout;
long long int n;
using namespace std;
string reverse(string k) //function to reverse strings
{int size,i,j,temp,mid;
size=k.length();
mid=size/2;
for(i=0;i<mid;++i,j--)
{
temp=k[i];
k[i]=k[j];
k[j]=temp;
}
return k;
}
int main()
{
int l,m,p;
char*itr;
std::string a;
std::string b;
std::string c;
cin>>n;
while(n--)
{
cin>>a; //input string a
cin>>b; //input string b
a=reverse(a);
b=reverse(b);
l=atoi(a.c_str()); //creating integer from sting a
m=atoi(b.c_str()); //creating integer from sting b
p=l+m; //adding integers
stringstream ss; //using stringstream ss to create string from integer
ss<<p;
c=ss.str();
c=reverse(c); //reversing the string
cout<<c<<"\n"; //outpu
}
return 0;
}
Thanks