I was solving this question on spoj-
https://www.spoj.com/problems/ABSYS/I compiled the code on geeks for geeks online compiler and it gave correct output (
https://ide.geeksforgeeks.org/P0gWlUy4Yg ), but codeblocks gave wrong output for last case.
I also submitted the solution on spoj, and the solution got accepted.
The expected output is:
23 + 47 = 70
3247 + 502 = 3749
1613 + 75425 = 77038
I compiled the code on codeblocks and it is showing output as:
23 + 47 = 70
3247 + 502 = 3749
1613 + 75424 = 77037As you can see, the third test case gives wrong output, which i have highlighted.
I am using version 17.12 of codeblocks on windows 10, and this is the first time something like this occurred. can anyone clarify, where the problem is ? is it codeblocks error/bug or some compiler error ?
I have attached the screenshot of my codeblocks output.
Following is my code:#include<bits/stdc++.h>
using namespace std;
int main()
{
string s,s1,s2,s3;
long long int t,i,j,k,f,a,b,T;
cin>>T;
cin.ignore();
while(T--)
{
cin.ignore();
getline(cin,s);
for(i=0; ; i++)
{
if(s[i]==' ')
{
s1=s.substr(0,i);
//cout<<s1<<" ";
break;
}
if(s[i]=='m')
f=1;
}
for(j=i+3; ; j++)
{
if(s[j]==' ')
{
s2=s.substr(i+3,j-i-3);
//cout<<s2<<" ";
break;
}
if(s[j]=='m')
f=2;
}
for(k=j+3; ; k++)
{
if(s[k]=='\0')
{
s3=s.substr(j+3,k-j-3);
//cout<<s3<<" ";
break;
}
if(s[k]=='m')
f=3;
}
if(f==1)
{
t=s2.size();
a=0;
b=0;
for(i=0; i<s2.size(); i++)
{
a=a+((s2[i]-'0')*pow(10,--t));
}
t=s3.size();
for(i=0; i<s3.size(); i++)
{
b=b+(s3[i]-'0')*pow(10,--t);
}
cout<<b-a<<" + "<<a<<" = "<<b<<"\n";
}
if(f==2)
{
t=s1.size();
a=0;
b=0;
for(i=0; i<s1.size(); i++)
{
a=a+(s1[i]-'0')*pow(10,--t);
}
t=s3.size();
for(i=0; i<s3.size(); i++)
{
b=b+(s3[i]-'0')*pow(10,--t);
}
cout<<a<<" + "<<b-a<<" = "<<b<<"\n";
}
if(f==3)
{
t=s1.size();
a=0;
b=0;
for(i=0; i<s1.size(); i++)
{
a=a+(s1[i]-'0')*pow(10,--t);
}
t=s2.size();
for(i=0; i<s2.size(); i++)
{
b=b+(s2[i]-'0')*pow(10,--t);
}
cout<<a<<" + "<<b<<" = "<<a+b<<"\n";
}
}
}