WA in SWPDGT

every one code is giving output 927 why?
1
917 9

997 +1=998 should be a answer?

this is not even a valid test case 917 > 99
may be, every other code only considering for maximum 2 decimal digits

ohk sorry missed that constraint

Why output of 1 99 is not 181 as sum of 91+90???
while output of 5 49 is 135 as sum of 95+40.
@hasinfarhan PLZ explain.

https://www.codechef.com/viewsolution/30846062
Please tell what is wrong here?

Can someone what is wrong with my code ->

#include <bits/stdc++.h>

int main(){
int t;
cin>>t;
while(t>0){
int A,B;
cin>>A>>B;
int Ac=A,Bc=B;
int y = A%10;
Ac=A/10;
int x = Ac%10;

    int a = B%10;
    Bc=B/10;
    int b = Bc%10;

    int ans=A+B;

    if(A<10&&B<10){
        ans = A+B;
    }else if(A < 10 && B >= 10){
        ans = max(ans, y + a*10 +b);
        ans = max(ans, a + y*10 + b);
        ans = max(ans,b + a*10 + y);
    }else if(B<10 && A>= 10){
        ans = max(ans, b + x*10 +y);
        ans = max(ans, x + b*10 + y);
        ans = max(ans,y + x*10 + b);
    }else{
        ans = max(ans, a*10 + y + x*10 + b);
        ans = max(ans, b*10 + y + a*10 + x);
        ans = max(ans, x*10 + a + y*10 + b);
        ans = max(ans, x*10 + b + a*10 + y);
    }
    cout<<ans<<"\n";
    t--;
}
return 0;

}

Check your answer for a=4 and b=5. Your code will give answer 54 but answer should be 9.

1 Like

You are not taking care of cases in which one number is single digit and other number is double digit. Eg. 13 and 3 should give answer 34 but you code is giving answer 16.

thank you so much i got my mistake.

Thanks, I think I got it

Output of 5 49 is 63.

Simple solution using string as input format.

link :- CodeChef: Practical coding for everyone

https://www.codechef.com/viewsolution/30851623

For which case is this giving wrong answer.
(I’m using Python)

Your code is giving wrong answer for case 18 and 37. Its answer should be 109 but your code gives answer 100. Reason behind is that your code changes number to 13 and 87 but actually it should change numbers to 78 and 31.

Thanks a lot for the reply. Would it be better to add more cases to my code or should I go for brute force method by applying a nested for loop?

I am still not able to figure out the wrong test case.
I tries all test cases mentioned in the previous replies.
Any help

here is my code:

#include <bits/stdc++.h>
using namespace std;
int main()
{
int test;
scanf("%d",&test);
while(test–)
{
int a,b;
int maxi=INT_MIN;
scanf("%d%d",&a,&b);
vector v1;
vector v2;
while(a>0)
{
v1.push_back(a%10);
a=a/10;
}

	while(b>0)
	{
		v2.push_back(b%10);
		b=b/10;
	}
	if(v1.size()>1)
	{
	swap(v1[0],v1[1]);
	}
    if(v2.size()>1)
	{
	swap(v2[0],v2[1]);
    }

	for(int i=0;i<v1.size();i++)
	{
		int temp_1=v1[i];
       for(int j=0;j<v2.size();j++)
       {
       	  int temp_2=v2[j];
          string str_1,str_2,ans="",str_3,str_4,ans_1="";
       	  swap(v1[i],v2[j]);
       	  if(v1.size()>1)
       	  {
       	  str_1 = to_string(v1[0]);
       	  str_2 = to_string(v1[1]);
       	  ans=str_1+str_2;
       	  }
       	  else
       	  {
       	  	 str_1 = to_string(v1[0]);
       	  	 ans=ans+str_1;
       	  }
          
          if(v2.size()>1)
          {
       	   str_3 = to_string(v2[0]);
       	   str_4 = to_string(v2[1]);
           ans_1=str_3+str_4;
          }
          else
          {
          	str_3 = to_string(v2[0]);
            ans_1=ans_1 + str_3;	
          }
          int myint1 = stoi(ans);
          int myint2 = stoi(ans_1);

          maxi=max(maxi,myint1+myint2);

          v1[i]=temp_1;
          v2[j]=temp_2;
       }    
	}
	printf("%d", maxi);
	printf("\n");
}
return 0;

}

1 Like

@ajaymalik posted that output for 5 49 is 135 in above comments. And you @hasinfarhan are saying that output for 5 49 is 63 .HOW???

Answer for 50 49 will be 135, swap 5 and 9

can someone explain whats wrong in the following code ?

#include <stdio.h>
int main()
{
int T;
scanf("%d",&T);
for(int k=0;k<T;k++)
{
int A,B,At,Ao,Bt,Bo;
int S1,S2,S3,S4;
scanf("%d %d",&A,&B);
At=A/10;
Ao=A%10;
Bt=B/10;
Bo=B%10;
S1=A+B;
S2=At10+Bt+Ao10+Bo;
S3=Bt10+At+Bo10+Ao;
if(S1>=S2&&S1>=S3)
printf("%d",S1);
else if(S2>=S1&&S2>=S3)
printf("%d",S2);
else if(S3>=S1&&S3>=S2)
printf("%d",S3);
}
}