Basic exercises - the string comparison


title: basic exercises string comparison
categories:

  • ACM
  • Logical
    tags:
  • Determine conditions has
    date: 2020-03-14 18:12:05

First, a good judgment, and 234 and an opposite (set if else), look 2, in order to be completely finished contrast; 34 as long as the output can not satisfied, it is judged in the preceding 2 to 34, according to a logical topic , in the first four to three. Thus the logic clear.

problem

Questions underlying string comparison exercises

By submitting this question

Resource constraints

Time limit: 1.0s Memory Limit: 512.0MB

Problem Description

Given two strings of only uppercase or lowercase letters (a length between 1 and 10), the relationship between them is one of the following 4 conditions:
  unequal length two strings: 1. For example Beijing and Hebei
  2: only two strings of equal length, but also the character at the corresponding position exactly (case sensitive), such as Beijing and Beijing
  . 3: two strings of equal length, only the character at a corresponding position are not distinguished under the premise of the case in order to achieve exactly the same (that is, it does not meet the case 2). For example beijing and beijing
  . 4: the length of the two strings are equal, but even these can not case sensitive nor two identical strings. Beijing and Nanjing such
  a relationship between two input strings programming determines which category of these four given class number belongs.

Input Format

Includes two rows, each row is a string

Output Format

Only a number, indicating the relationship between the two strings of numbers

Sample input

BEIjing

beiJing 

Sample Output

3

algorithm

#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main(){	
//freopen("input.txt", "r", stdin);
	char a[10],b[10];
	cin>>a>>b;
	if(strlen(a)!=strlen(b))
	cout<<"1";
	else{
		for(int i=0;i<strlen(a);i++)
		{
			int t=a[i]-b[i];
			if(!(t==32||t==-32||t==0))
			{cout<<"4";return 0;
			}
			else if(t!=0)
			{
				cout<<"3";
				return 0;
			}
			
		}
		cout<<"2";
	}
	return 0;
}
Published 43 original articles · won praise 1 · views 908

Guess you like

Origin blog.csdn.net/qq_43985303/article/details/105150171