T1114 Case-ignoring string comparison#計間客C++

T1114 string comparison ignoring case

Title description

Generally, we strcmpcan compare the size of two strings. The comparison method is to compare the two strings character by character from the front to the back (compare according to the ASCII code value) until a different character appears or is encountered '\0'. If all the characters are the same, they are considered the same; if there are different characters, the comparison result of the first different character shall prevail (Note: If a string is encountered '\0', and another string has not yet been encountered To '\0', the former is smaller than the latter).

But sometimes, when we compare the size of the string, you want to ignore the size of the letters, for example, "Hello"and "hello"when the capitalization is equal. Please write a program to compare the case of two strings, ignoring the case of letters.

Input format

The input is two lines, one string per line, two strings in total. (Each string is less than 80 in length and only contains uppercase and lowercase letters)

Output format

If the first string is smaller than the second string, output a character "<";

If the first string is larger than the second string, output a character ">";

If the two strings are equal, a character "=" is output.

Sample input

Hellohowareyou
helloHowareyou

Sample output

 =

Code

#include <iostream>
#include <string>
#include <cstring>
using namespace std;

int main(){
    
    
	char s[90],c[90];
	cin >> s >> c;
	
	int slen = strlen(s);
	int clen = strlen(c);
	
	for(int i=0; i<slen; i++){
    
    
		if(s[i]>='A' && s[i]<='Z')
			s[i] = s[i]+32;
	}
	for(int i=0; i<clen; i++){
    
    
		if(c[i]>='A' && c[i]<='Z')
			c[i] = c[i]+32;
	}
	
 	int flag = strcmp(s,c);
    if (flag == 0) cout << "=" << endl;
    else if (flag > 0) cout << ">" << endl;
    else cout << "<" << endl;
	
	return 0;
} 

Guess you like

Origin blog.csdn.net/qq_44524918/article/details/108718425