Openjudge 2721 compares string size with Case sensitivity

Source: Internet
Author: User

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

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.