Blue Bridge Cup - basic exercises string comparison

String comparison

Problem description
  given only by two strings 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 of
output format
  only a number indicating the number of the relationship between these two strings
Sample Input

Beijing
beijing

Sample Output

3

Complete code:

#include<cstring>
#include<iostream>
using namespace std;
int main()
{
    string a,b;
    cin>>a;
    cin>>b;
    int lena=a.size();
    int lenb=b.size();
    if(lena!=lenb)
    {
        cout<<"1"<<endl;
    }
    else
    {
        if(a==b)
            cout<<"2"<<endl;
        else
        {
            int f=0;
            for(int i=0; i<lena; i++)
            {
                if((a[i]+32==b[i])||(a[i]-32==b[i])||(a[i]==b[i]))
                {
                    f++;
                }
            }
            if(f==lena)
                cout<<"3"<<endl;
            else
                cout<<"4"<<endl;
        }
    }
    return 0;
}

Published 87 original articles · 98 won praise · views 4938

Guess you like

Origin blog.csdn.net/qq_45856289/article/details/105104466