蓝桥杯 基础练习 字符串对比 (vip)

基础练习 字符串对比

蓝桥杯 基础练习 字符串对比 (vip)_第1张图片

方法一

#include
#include
using namespace std;
int main()
{
    char s1[20],s2[20];
    cin>>s1;
    cin>>s2;
    int str1,str2;
    str1=strlen(s1);
    str2=strlen(s2);
    if(str1!= str2)
    {
        cout<<"1";
    }
    else if(str1==str2&&strcmp(s1,s2)==0)
    {
        cout<<"2";

    }
    else if(str1==str2&&strcmp(s1,s2)!=0&&strcasecmp(s1,s2)==0 )
    {
        cout<<"3";

    }
    else
        cout<<"4";
//    cout<

方法二

#include
using namespace std;
int main()
{
     char a[20],b[20];
   cin>>a;
   cin>>b;
    int l1=strlen(a);
    int l2=strlen(b);
    int i;
    int s[100];
    if(l1 != l2)
    {
        printf("1");
    }
    else
    {
        for( i=0; i='a'&&a[i]<='z')
                    a[i]=a[i]-'a'+'A';
                if(b[i]>='a'&&b[i]<='z')
                    b[i]=b[i]-'a'+'A';
                if(a[i]!=b[i])
                {
                    printf("4");
                    return 0;
                }
                else
                {
                    s[i]=1;
                }
            }
            else
            {
                s[i]=0;
            }
        }
        int n=0;
        for( i=0;i0)
            printf("3");
        else
            printf("2");

    }
    return 0;
}

 

你可能感兴趣的:(蓝桥杯)