Question #99427

Print the two strings in alphabetical order. Assume the strings are lowercase. End with newline. Sample output:
capes rabbits
#include <iostream>
#include <string>
using namespace std;

int main() {
string firstString;
string secondString;

cin >> firstString;
cin >> secondString;

/* Your solution goes here */

return 0;
}

Expert's answer

#include <iostream>

#include <string>

#include <windows.h>


using namespace std;


void printAlfabet(string first, string second);



int main()

{

  string firstString;

  string secondString;

  cin >> firstString;

  cin >> secondString;

  printAlfabet(firstString, secondString);

  return 0;

}



void printAlfabet(string first, string second)

{

  if(first[0] > second[0])

  {

    cout << second << " " << first;

  }

  else

    cout << first << " " << second;

}



LATEST TUTORIALS
APPROVED BY CLIENTS