VIP test questions basic practice string comparison (C language)

Problem Description

  Given two strings consisting of only uppercase or lowercase letters (with a length between 1 and 10), the relationship between them is one of the following four situations:
  1: The two strings have different lengths. For example, Beijing and Hebei
  2: The two strings are not only equal in length, but the characters in the corresponding positions are exactly the same (case sensitive), such as Beijing and Beijing
  3: The two strings are equal in length, and the characters in the corresponding positions are only indistinguishable Only under the premise of capitalization can be fully consistent (that is, it does not satisfy Case 2). For example, beijing and BEIjing
  4: The two strings are equal in length, but even if it is case-insensitive, the two strings cannot be the same. For example, Beijing and Nanjing
  program to determine which of these four types the relationship between the two input strings belongs to, and give the number of the type to which they belong.
Input format
  Include two lines, each line is a string
Output format
  There is only one number, indicating the relationship number of the two strings
Sample input
BEIjing
beijing
Sample output
3
 

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
	char s1[10],s2[10];
	int l1,l2,i,j,k;
	int f=0;
	
	scanf("%s%s",s1,s2);
	l1=strlen(s1);
	l2=strlen(s2);
	
	if(l1!=l2)
	printf("1");
	else if(strcmp(s1,s2)==0)
	printf("2");
	else if(strcmp(strlwr(s1),strlwr(s2))==0)
	printf("3");
	else
	printf("4");
		
		
	
	return 0;
	
 } 

The function of the strlwr function is to convert the S parameter in the string to lowercase.

Guess you like

Origin blog.csdn.net/with_wine/article/details/114991066