I tried to do this question using strings and I am getting correct answers for the test cases on my compiler but spoj says Wrong answer.
I tried the hidden test case 0,0 and handled that too , still I am getting a wrong answer
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int t=0,x=0,y=0,z=0,i=0;
cin>>t;
string s1,s2,s3;
while(t--)
{
cin>>s1>>s2;
reverse(s1.begin(),s1.end());
reverse(s2.begin(),s2.end());
x=stoi(s1);
y=stoi(s2);
z=x+y;
s3=to_string(z);
if(z!=0)
{
for(i=0;s3[i]!='\0';i++)
{
if(s3[i]=='0')
{
s3[i]='\0';
break;
}
}
reverse(s3.begin(),s3.end());
}
cout<<s3<<endl;
}
}
I got correct answers on my compiler but when I submitted the same code on spoj , I got wrong answer. Could this be because the the website expected answer in int and I have printed Answer as String ?