WA in SWPDGT

#include<bits/stdc++.h>
using namespace std;
int swap(int *x,int *y)
{
int temp=*x;
*x=*y;

*y=temp;

}
int count1(int a[])
{
int count=0;
int p=a[0]+a[2];
p=p*10;
count=p+a[1]+a[3];
return count;
}
int solve(int a[])
{
int first=0,t,p;

    for(int i=0;i<4;i++)
    {   
        if(first<=a[i])
        {
            first=a[i];
            t=i;
        }
    }
    if(t==0 || t==2)
    {   if(a[t+1]>a[(t+2)%4])
        {
         swap(&a[t+1],&a[(t+2)%4]);
        }
       
        p=count1(a);
    }
    else
    {
        swap(&a[t],&a[(t+1)%4]);
        p=count1(a);
    }
    return p;

}

int main()
{
int t;
cin>>t;
while(t–)
{
int a,b;
cin>>a>>b;

    int arr[4];
    arr[1]=a%10;
    a=a/10;
    arr[0]=a%10;
    
    arr[3]=b%10;
    b=b/10;
    arr[2]=b%10;
    
    int k=solve(arr);
    cout<<k<<"\n";
    
}

}

Have you considered taking single digit numbers both, and a mix of single and double digit? I think its taking the zero of single digit numbers in the array and swapping to create a two digit number.

No need of such bulky code. Only four lines are enough. Look at my code. Comments are there for reference. Hpoe it helps.
https://www.codechef.com/viewsolution/30814498

3 Likes

Thank you sir but I want to know about the test case that is not passed by my code.

Yes sir but it gives correct ans at all. Can you suggest some test case which is not fulfilled by my code?

see in your code
test case is 3 5
its answer should be 8 but your code is giving it as 53
see the mistake and rectify it