16: case-insensitive string comparison, and case-insensitive string comparison
16: case-insensitive string comparison
- View
- Submit
- Statistics
- Question
-
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 the 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 (note: if a string encounters '\ 0' while another string does not, the former is smaller than the latter ). However, in some cases, we compare the size of strings and want to ignore the size of letters. 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. (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, the output is a character "= ".
-
Sample Input
-
Hello, how are you?hello, How are you?
-
Sample output
-
=
-
Source
-
Computing overview 05
-
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int main(){ char a[81],b[81],c[81];int d=0,e=0;gets(a);gets(b);for (int i=0;i<=strlen(a);++i){if (a[i]<='Z'&&a[i]>='A'){a[i]=a[i];}if (a[i]<='z'&&a[i]>='a'){a[i]=a[i]-32;}}for (int i=0;i<=strlen(b);++i){if (b[i]<='Z'&&b[i]>='A'){b[i]=b[i];}if (b[i]<='z'&&b[i]>='a'){b[i]=b[i]-32;}}for (int i=0;i<=strlen(a);++i){if (a[i]==b[d]){e=1;}elseif (a[i]>b[d]){e=0;cout<<">";break;}elseif (a[i]<b[d]){e=0;cout<<"<";break;}d++;}if (e==1)cout<<"=";return 0;}