i have written the code for the ADDREV problem, and is working fine for all cases in my system ,but here it is showing wrong answer , please can somebody help
created
last reply
- 16
replies
- 1.7k
views
- 6
users
- 1
like
i have written the code for the ADDREV problem, and is working fine for all cases in my system ,but here it is showing wrong answer , please can somebody help
void main()
{
int x,y,b1,b2,b3,s1=0,s3=0,s2=0,s4=0,i,n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d\t%d",&x,&y);
while(x!=0)
{
b1=x%10;
s1=(s1*10)+b1;
x=x/10;
}
while(y!=0)
{
b2=y%10;
s2=(s2*10)+b2;
y=y/10;
}
s3=s1+s2;
while(s3>0)
{
b3=s3%10;
s4=(s4*10)+b3;
s3=s3/10;
}
printf("%d\n",s4);
s1=0;
s2=0;
s4=0;
}
}
this is my code can someone help me to solve the runtime error
#include<bits/stdc++.h>
using namespace std;
void revsu(string &,string &);
void fuglo(string &,int);
int main()
{
string a,b;
int N;
cin>>N;
if(N>=1&&N<=10000)
while(N–)
{
cin>>a>>b;
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
// cout<<"\n";
revsu(a,b);
cout<<"\n";
}
return 0;
}
void revsu(string &a,string &b)
{
string p(‘0’,0);
int g,t,m,n,s=0,k=0,i,j,car=0;
m=a.size();
n=b.size();
k=m>n?m+1:n+1;
t=k;
p.resize(k);
p[k]=’\0’;
i=m-1;
j=n-1;
if(m>n)
{
while(i>=0&&j>=0)
{
k–;
s=(a[i]-‘0’)+(b[j]-‘0’)+car;
p[k]=(s%10)+48;
car=s/10;
i–;
j–;
//cout<<p[k];
}
while(i>=0)
{
k–;
s=(a[i]-‘0’)+car;
p[k]=(s%10)+48;
car=s/10;
i–;
//cout<<p[k];
}
if(car>0)
{
k–;
p[k]=‘1’;
//cout<<p[k];
}
}
else
{
while(i>=0&&j>=0)
{
k–;
s=(a[i]-‘0’)+(b[j]-‘0’)+car;
p[k]=(s%10)+48;
car=s/10;
i–;
j–;
//cout<<p[k];
}
while(j>=0)
{
k–;
s=(b[j]-‘0’)+car;
p[k]=(s%10)+48;
car=s/10;
j–;
//cout<<p[k];
}
if(car>0)
{
k–;
p[k]=‘1’;
// cout<<p[k];
}
}
fuglo(p,t);
/* for(int g=0;g<t;g++)
{
if(p[g]==‘0’)
ff++;
}
//cout<<ff<<"\n";
if(ff==(t-2))
cout<<p[ff];
//else
//{
for(int o=t-1;o>=0;o--)
{
cout<<p[o];
}
//}*/
}
void fuglo(string &f,int u)
{
int k=0;
reverse(f.begin(),f.end());
if(f[0]==‘0’)
{
for(int i=1;i<u;i++)
{
if(f[i]!=‘0’)
{
k=i;
break;
}
}
for(int m=k;m<u;m++)
cout<<f[m];
}
else
{
for(int k=0;k<u;k++)
cout<<f[k];
}
}
my code is showing wrong answer but I think I have covered all test cases please help…
Topic | Category | Replies | Views | Activity |
---|---|---|---|---|
What am i Missing | ProblemSet Archive | 1 | 156 | Feb 22 |
What are allowed characters in task t9 | ProblemSet Archive | 4 | 212 | Feb 24 |
Getting WA on the problem PIE continuously, what am I missing? spoj.com | ProblemSet Archive | 2 | 172 | Mar 8 |
COT - Count on a tree - TLE | ProblemSet Archive | 1 | 127 | Mar 18 |
Beangame | ProblemSet Archive | 2 | 123 | Apr 9 |