zoukankan      html  css  js  c++  java
  • Gym

    Islam is usually in a hurry. He often types his passwords incorrectly. He hates retyping his password several times whenever he tries to login, especially that his passwords are usually very long. He believes that websites should be tolerant with very long passwords. In other words, he believes that if a password is very long, and there is only one mistake in the password, the website should allow the user to login.

    Your task is to check if an entered password should be accepted according to Islam, or not. The entered password will be accepted if it matches the user’s password, or if the user’s password length is at least 8 characters and the user made a mistake with only one character (either replaced it with a wrong character or dropped it).

    Given the user’s password, and the entered password, determine if the entered password should be accepted according to Islam.

    Input

    The first line of input contains the user’s password.

    The second line of input contains the entered password.

    Both strings contain only lowercase and uppercase English letters.

    The length of each string is at least 1 and at most 100.

    Output

    Print yes if the entered password should be accepted according to Islam, otherwise print no.

    Examples

    Input
    AgentMahone
    IslamIsMahone
    Output
    no
    Input
    ofmahone
    ofmahome
    Output
    yes
    Input
    algorithms
    algorthms
    Output
    yes
    Input
    Mahone
    mahonE
    Output
    no

    题意:输入两个字符串,如果第一个字符串的位数为8位以下,则两个字符串必须完全相同才输出“yes”,否则输出“no”。当第一个字符串的长度大于8位时,则第二个字符串可以比第一个字符串少一个字符,或与第一个字符串一个字符不相同,输出即为“yes”,其余情况均输出“no”。
    题解:可分为四种情形,我们可以对其逐一进行判断,第一种:是第一个字符串比第二个字符串多两个字符,或者第二个字符串比第一个字符串多,即输出“no”;第二种,第一个字符串长度小于8,两个字符串必须完全相同才“yes”;第三种,两个字符串长度相等,定义一个变量flag,对其不相同的次数进行计数,超过2即为“no”;第四种就是第一个字符串比第二个字符串多1个字符的情形。注意:各种情形的判断顺序不可随意调动。具体情况详见代码所示:
    #include<iostream> 
    #include<cstdlib>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<stack>
    #include<queue>
    #define ll long long
    using namespace std;
    int main(){
        string s1,s2;
        cin>>s1>>s2;
        int flag=0;
        int a=s1.length(),b=s2.length();
        if(a<b||a-b>1) cout<<"no"<<endl;
        else if(a<8)
        {
            if(s1==s2) cout<<"yes"<<endl;
            else cout<<"no"<<endl;
        }
        else if(a==b)
        {
            for(int i=0;i<a;i++)
            {
                if(s1[i]!=s2[i]) flag++;
            }
            if(flag>1) cout<<"no"<<endl;
            else cout<<"yes"<<endl;
        }
        else
        {
            int num1=0,num2=0;
            while(num1<a&&num2<b)
            {
                if(s1[num1]!=s2[num2])
                {  //当第一个字符串比第二个多一个字符时,不一样时,只增加第一个字符串的下标 
                    num1++;
                    flag++;
                }
                else
                {
                    num1++;
                    num2++;
                }
                if(flag==2) break;
            }
            if(flag==2) cout<<"no"<<endl;
            else cout<<"yes"<<endl;
        }
        return 0;
    }
  • 相关阅读:
    图像处理之基础---卷积及其快速算法的C++实现
    嵌入式c语言笔试
    逻辑题
    多媒体开发之---h264 图像参数级语义
    多媒体开发之---h264 取流解码实现
    多媒体开发之---live555 分析客户端
    多媒体开发之---如何确定slice_header slice_type 的位置
    图像处理之基础---很好的一个开源文档库
    多媒体开发之---h264 高度和宽度获取
    Flutter实战视频-移动电商-65.会员中心_订单区域UI布局
  • 原文地址:https://www.cnblogs.com/zjl192628928/p/9273091.html
Copyright © 2011-2022 走看看