1. Link:
Http://bailian.openjudge.cn/practice/2721/
2. content:
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kb
-
Description
-
Generally, we can use strcmp to compare the size of two strings. The comparison method is to compare the two strings one by one from the beginning and the end (compare by ASCII value ), until different characters or '\ 0' are displayed. If all characters are the same, they are considered to be the same. If there are different characters, the comparison result of the first different characters prevails. However, sometimes we want to ignore the size of letters when comparing character strings. For example, "hello" and "hello" are equal when ignoring uppercase and lowercase letters. Write a program to compare the two strings with uppercase or lowercase letters.
-
Input
-
The input is a string of two lines, each of which is a string. (Use gets to enter each line of strings) (each string must be less than 80 characters in length)
-
Output
-
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, output a character "="
-
Sample Input
-
Hellohello
-
Sample output
-
=
-
Source
-
Introduction to computing final exams of the School of Chemistry
3. Method:
This question is only intended to test programming in Linux. It does not make any sense.
4. Code:
1 #include <iostream> 2 #include <string> 3 #include <cstring> 4 5 using namespace std; 6 7 int main(void) 8 { 9 string str1,str2;10 getline(cin,str1);11 getline(cin,str2);12 13 //cout << str1 << endl;14 //cout << str2 << endl;15 16 string::size_type str_i;17 for(str_i = 0; str_i != str1.size(); ++str_i)18 { 19 if(str1[str_i] >= ‘a‘ && str1[str_i] <= ‘z‘) str1[str_i] = str1[str_i] - ‘a‘ + ‘A‘;20 } 21 22 for(str_i = 0; str_i != str2.size(); ++str_i)23 { 24 if(str2[str_i] >= ‘a‘ && str2[str_i] <= ‘z‘) str2[str_i] = str2[str_i] - ‘a‘ + ‘A‘;25 } 26 if(str1 == str2) cout << "=" << endl;27 else if(str1 < str2) cout << "<" << endl;28 else cout << ">" << endl;29 return 0;30 }
Openjudge 2721 compares string size with Case sensitivity