当前位置 : 主页 > 大数据 > 区块链 >

ECJTU 2018 Summer Training

来源:互联网 收集:自由互联 发布时间:2021-06-22
E. Accepted Passwords(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

                        E. Accepted Passwords(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
这道题先讨论字母长等长的情况,在讨论错的字母数。再讨论只大于一个字母的情况,再讨论错误的字母数。请他情况都是NO;
 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cmath>
 4 #include<string>
 5 #define max 100000+2
 6 using namespace std;
 7 int main()
 8 {
 9     string a,b;
10     while(cin>>a>>b)
11     {
12         int ans;
13         int l1=a.size();
14         int l2=b.size();
15         if(l1==l2)
16         {
17             ans=0;
18             for(int i=0;i<l1;i++)
19             {
20                 if(a[i]!=b[i])
21                     ans++;
22             }
23             if((ans==1&&l1>=8)||ans==0)
24             {
25                 cout<<"yes"<<endl;
26             }
27             else
28             cout<<"no"<<endl;
29         }
30         else if(l1-l2==1&&l1>=8)
31         {
32             int j=0;ans=0;
33             for(int i=0;i<l1;i++)
34             {
35                 if(a[i]!=b[j])
36                 {
37                     ans++;
38                     j--;
39                 }
40                 j++;
41             }
42             if(ans==1)
43             {
44                 cout<<"yes"<<endl;
45             }
46             else
47             {
48                 cout<<"no"<<endl;
49             }
50         }
51         else 
52         cout<<"no"<<endl;
53     }
54 }
View Code
网友评论