天天看點

Gym - 100989E

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;
}      

轉載于:https://www.cnblogs.com/zjl192628928/p/9273091.html