View Code of Problem 78

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

bool cmp(string a ,string b){
    for(int i=0;i<a.length()&&i<b.length();i++){
        if(a[i]!=b[i]){
            return a[i]<b[i];
        }
        if(i==a.length()-1) return true;
        if(i==b.length()-1) return false;
    }

}

int main(){
    
    string str[3];
    for(int i=0;i<3;i++)
    cin>>str[i];
    sort(str,str+3,cmp);
    for(int i=0;i<3;i++)
    cout<<str[i]<<endl;












    return 0;
}

Double click to view unformatted code.


Back to problem 78