SWPDGT - SWPDGT Problem - CodeChef
Below is my code for the question, I am unable to understand why am I getting wrong answer. Which testcase am I missing ?
#include<bits/stdc++.h>
using namespace std;
void swapOnce(int a, int b){
int o1, t1, o2, t2;
o1 = a%10;
t1 = a/10;
o2 = b%10;
t2 = b/10;
int total = 0;
//cout<<"\nBefore swap "<<t1<<o1<<" "<<t2<<o2;
if(t1 == 0 && t2 == 0){
//reconstruct the number
cout<<"\nAfter swap "<<t1<<o1<<" "<<t2<<o2;
total = ((t1+t2)*10) + (o1+o2);
cout<<"\n"<<total;
}
else
{
if(o1 > t2 && o2<=t1){
int temp = o1;
o1 = t2;
t2 = temp;
}
else if(o2 > t1 && o1<=t2){
int temp = o2;
o2 = t1;
t1 = temp;
}
else if(o1 > t2 && o2 > t1)
{
if((o1 - t2) > (o2 - t1)){
int temp = o1;
o1 = t2;
t2 = temp;
}
else
{
int temp = o2;
o2 = t1;
t1 = temp;
}
}
else
{
//do nothing
}
//reconstruct the number
cout<<"\nAfter swap "<<t1<<o1<<" "<<t2<<o2;
total = ((t1+t2)*10) + (o1+o2);
cout<<"\n"<<total;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
// cout<<"\nEnter the testcases";
cin>>t;
while (t--)
{
int a, b;
cin>>a>>b;
swapOnce(a,b);
}
return 0;
}