1 / 17
Jan 2010

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

    Jan '10
  • last reply

    Aug '19
  • 16

    replies

  • 1.7k

    views

  • 6

    users

  • 1

    like

well i modified my code but still it shows same Wrong Answer.
here is my modified code:

What test cases have you tried? Don't forget that is the most important part of problem solving. Maybe you should test something where cases_int = 2.

well then i have tried all possible cases i could think of but it is giving the right answer in my system, could you please help ? i tried with cases_int = 5 and it's working fine

6 months later

hi....

my code its work fine with input
2
999 11
101
999 11
101

but the system still judge wrong answer .... could someone help me frowning

tq

i did it, i have AC from the judge. All i do is change my reversing algorithm from using a string operation become integer operation smile tq guys

5 years later

include

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 blush

Please edit your post. Select all of the code and then click the preformatted text button.

What kind of runtime error are you getting?

3 years later

#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…

Please use the [code] and [/code] tags to keep your code format, this is unreadable.