Petya And String

A. Petya and Strings

A problem for the code forces.
And my c++ solution for this question.

A breif on question.

Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.



#include <iostream>

#include <cctype>

using namespace std;

int main(){

string a, b;

cin >> a;

cin >> b;

for(int i = 0; i <a.size(); i++){

a[i] = tolower(a[i]);

b[i] = tolower(b[i]);

}

if(a.size() <= 100 && a.size() >= 1){

if(a == b){ cout << 0 << endl;

}else if (a < b){cout << -1 << endl;

}

else {cout << 1 << endl;

}

}

    return 0;

}


My Output:



Post a Comment (0)
Previous Post Next Post