16: case-insensitive string comparison, and case-insensitive string comparison

Source: Internet
Author: User

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;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.