lundi 22 mars 2021

how to sort 3 strings with only 3 if statement (C++)

I need help comparing 3 strings but using only 3 if statements

I was able to write using 5 if statements

I will be very grateful if anyone knows how to solve it

string a, b, c;
if( a>b && a>c ){
  if(b>c)
    cout << a << b << c;
  else
    cout << a << c << b;
}
else if( b>c && b>a ){
  if(a>c)
    cout << b << a << c;
  else
    cout << b << c << a;
}
else{
   if(a>b)
    cout << c << a << b;
  else
    cout << c << b << a;
}

Aucun commentaire:

Enregistrer un commentaire