C language · Character Turn comparison

Source: Internet
Author: User

The problem description is given two strings that consist of only uppercase or lowercase letters (between 1 and 10), and the relationship between them is one of the following 4 cases:
1: Two string lengths are different. Like Beijing and Hebei.
2: Two strings are not only equal in length, but the characters are exactly the same (case sensitive), such as Beijing and Beijing
3: Two strings are equal in length, and the characters at the corresponding positions can be fully consistent only if they are not case-sensitive (that is, it does not satisfy case 2). Like Beijing and Beijing.
4: Two strings are equal in length, but even case insensitivity does not make the two strings consistent. Like Beijing and Nanjing.
The programming determines which of the four classes the relationship between the input two strings belongs to, giving the number of the class to which it belongs. The input format consists of two lines, each of which is a string output format with only one number indicating the relationship number of the two strings sample input Beijing
Sample Output 3 Author's note: The built-in functions in C are not yet familiar to me. When you need to use the length of the input string, use the Strlen function and notice that the input string is placed in the character array.
1 /*2 1: Two string lengths are different. Like Beijing and Hebei .3 2: Two strings are not only equal in length, but the characters are exactly the same (case sensitive), such as Beijing and Beijing4 3: Two strings are equal in length, and the characters at the corresponding positions can be fully consistent only if they are not case-sensitive (that is, it does not satisfy case 2). Like Beijing and Beijing .5 4: Two strings are equal in length, but even case insensitivity does not make the two strings consistent. Like Beijing and Nanjing .6 */ 7#include <stdio.h>8#include <string.h>9 intMain ()Ten { One     Charch1[Ten],ch2[Ten]; Ascanf"%s%s", CH1,CH2); -     intLen1,len2; -len1=strlen (CH1); theLen2=strlen (CH2); -     if(len1==len2) -     { -         intflag=1;//identifiers +          for(intI=0; i<len1;i++) -             if(ch1[i]!=Ch2[i]) +flag=0;  A         if(flag) atprintf"2"); -         Else{ -flag=1;//identifier collocation -              for(intI=0; i<len1;i++)//determine if it is different if the case is ignored -             if(ch1[i]+ +!=ch2[i] && ch1[i]- +!=ch2[i] && ch1[i]!=ch2[i]) flag=0; -             if(flag) printf ("3");//Meet the criteria 3 in             Elseprintf"4");//Meet the criteria 4 -         } to     } +     Elseprintf"1"); -}

C language · Character Turn comparison

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.