# SWPDGT-my code is giving WA

my code is:
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t–)
{
int a,b;
cin>>a>>b;
if(a>=10&&b>=10)
{
int a1=a/10;
int a2=a%10;
int b1=b/10;
int b2=b%10;
if(b>a)
{
if(b2>a1)
{
cout<<(b210+a2)+(b110+a1)<<endl;
}
else
{
cout<<b+a<<endl;
}
}
else if(a>b)
{
if(a2>b1)
{
cout<<(a210+b2)+(a110+b1)<<endl;
}
else
{
cout<<a+b<<endl;
}
}
}
else if(a<10&&b<10)
{
cout<<a+b<<endl;
}
else
{
if(b>10&&a<10)
{
int b1=b/10;
int b2=b%10;
if(b1>=a)
{
cout<<b+a<<endl;
}
else
{
cout<<(a10+b2)+b1<<endl;
}
}
else if(a>10&&b<10)
{
int a1=a/10;
int a2=a%10;
if(a1>=b)
{
cout<<a+b<<endl;
}
else
{
cout<<(b
10+a2)+a1<<endl;
}
}
}
}
}

please tell me where the code is failing.or provide a test case where it gives wrong answer.

you have done lot of mistakes here check someof them :-
1.

you should change to " while(t–)"

here you should know that how multiplication works
it should be `cout<<(b2*10+a2)+(b1*10+a1)<<endl;`

apart from this if you try the test case :-
1
63 28

so your algorithm is not working properly

thanks for pointing out the test case. it was helpful.

Sir, please tell me where my code is wrong.Most of test case i tried is correct but still not getting A.C.
code:
//no
#include
using namespace std;
int main()
{
int t;cin>>t;
while(t–)
{
int a,b;
cin>>a>>b;
int a1,a0,b1,b0,sum=0;
a0=a%10;
b0=b%10;
a1=a/10;
b1=b/10;
if(a1>b0&&b1>a0)
{
sum=a+b;
}
else if(b0>=a0)
{
if(b0>=a1)
sum=(b010)+a0+(b110)+a1;
else if(a0>=b1)
sum=(a010)+b0+(a110)+b1;
}else if(a0>=b0)
{
if(a0>=b1)
sum=(a010)+b0+(a110)+b1;
else if(b0>=a1)
sum=(b010)+a0+(b110)+a1;
}
cout<<sum<<endl;
}
return 0;
}

your code is failing for test cases like
:-

1
9 7
correct output :- 16

rethink your approach you are pretty close

Thanks. I thought in single digit no we have to consider zero also.

1 Like

Bro, what is wrong in my code??
Need help.
@safalya7777777 @pkpawan123
https://www.codechef.com/viewsolution/30875049

bro only one swap of elements is allowed , take this testacase :
1
19 17

here there would be one swap between 9 and 1 and that will make it 11 and 97 so
correct output :- 108

i hope you got it

@pkpawan123 Yea bro… !!
Got AC!!
case 2 was wrong… !!
https://www.codechef.com/viewsolution/30882664

1 Like

well done bro…keep going

welcome bro.

Hi, can anyone find out why this code gives WA? It works on sample test cases…
https://www.codechef.com/viewsolution/30927096

Try

``````2
9 5
78 12
``````

Thanks bro…

https://www.codechef.com/viewsolution/32879931 i waana know my code fails it passes all my cases.Someone look into it.

#include <stdio.h>
int swap(int *x, int *y);
int main()
{
int t,m,n,i,digit1[5],digit2[5],temp,sum;
scanf("%d",&t);
for (i=0;i<t;i++){
scanf("%d %d",&m,&n);
if (m<n) swap(&m,&n);
digit1[1]=m/10;
digit1[0]=m-(digit1[1]*10);
digit2[1]=n/10;
digit2[0]=n-(digit2[1]*10);

``````    if (digit1[1]==0 && digit2[1]==0) sum=m+n;
``````

else {

``````    if (digit2[1]==0 && digit1[1]!=0){
if (digit2[0]>digit1[1]) swap(&digit2[0],&digit1[1]);
}
else if (digit1[1]!=0 && digit2[1]!=0){
if (digit2[0]>digit1[1] && digit2[0]>digit1[0]){
swap(&digit2[0],&digit1[1]);
}
else if (digit1[0]>digit2[1]){
swap(&digit1[0],&digit2[1]);

}

}
sum=(digit1[1]*10)+digit1[0]+(digit2[1]*10)+digit2[0];}
printf("%d\n",sum);
}
return 0;
``````

}
int swap(int *x, int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
return 0;
}
whats wrong with this code can anyone help me?