Gym 100989E 字符串

Description

standard input/output

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.

Sample Input

Input

AgentMahoneIslamIsMahone

Output

no

Input

ofmahoneofmahome

Output

yes

Input

algorithmsalgorthms

Output

yes

Input

MahonemahonE

Output

no

题意:

题解:给两个串a,b; a的长度len1 b的长度len2   a长度小于8的直接判断,长度大于等于8的 根据题意 两个串的长度只存在 len1==len2或者 len1-len2=1两种情况才可能yes,分别特判一下就可以了。   len1==len2情况下 只能是两个串相同或者某一个字母被替换,遍历一遍验证   len1-len2==1 情况下 只能是丢失一个字母  遍历一遍 当遇到字母不同时,b串向后移动一位继续遍历                        当只出现一次对应字母不同时,才能说明只丢失了一个字母
 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 using namespace std;
 5 char a[105];
 6 char b[105];
 7 int main()
 8 {
 9     scanf("%s",a);
10     scanf("%s",b);
11     int len1=strlen(a);
12     int len2=strlen(b);
13     if(len1<8)
14     {
15         if(strcmp(a,b)==0)
16             cout<<"yes"<<endl;
17         else
18             cout<<"no"<<endl;
19     }
20     else
21     {
22         if(len2>len1)
23         {
24             cout<<"no"<<endl;
25             return 0;
26         }
27         if(strcmp(a,b)==0)
28         {
29             cout<<"yes"<<endl;
30             return 0;
31         }
32         int flag=0;
33         if(len1==len2)
34         {
35             for(int i=0;i<len1;i++)
36             {
37                 if(a[i]!=b[i])
38                 {
39                     flag++;
40                 }
41             }
42             if(flag==1)
43             {
44                 cout<<"yes"<<endl;
45                 return 0;
46             }
47             else
48             {
49                 cout<<"no"<<endl;
50                 return 0;
51             }
52         }
53         if(len1-len2==1)
54         {
55         for(int i=0;i<len1;i++)
56         {
57             if(a[i]!=b[i])
58             {
59                 for(int j=len2-1;j>=i;j--)
60                 {
61                     b[j+1]=b[j];
62                 }
63                 b[i]=‘ ‘;
64                 flag++;
65             }
66         }
67           if(flag==1)
68             {
69                 cout<<"yes"<<endl;
70                 return 0;
71             }
72             else
73             {
74                 cout<<"no"<<endl;
75                 return 0;
76             }
77         }
78         cout<<"no"<<endl;
79     }
80     return 0;
81 }
时间: 2024-10-10 17:42:21

Gym 100989E 字符串的相关文章

UESTC 2016 Summer Training #1 Div.2

最近意志力好飘摇..不知道坚不坚持得下去.. 这么弱还瞎纠结...可以滚了.. 水题都不会做.. LCS (A) 水 LCS (B) 没有看题 Gym 100989C 水 1D Cafeteria (B) 不会捉 Gym 100989E 水 Gym 100989F 水 Mission in Amman (B) 没看题 Queue (A) 感觉题意理解得有问题啊 1 #include <iostream> 2 #include <cstdio> 3 #include <cstr

UESTC 2016 Summer Training #1 Div.2 E - Accepted Passwords 讨论

E - Accepted Passwords Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100989E Description standard input/output Islam is usually in a hurry. He often types his passwords incorrectly. He hates

ACM: Gym 100935B Weird Cryptography - 简单的字符串处理

Weird Cryptography Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Gym 100935B Description standard input/output Khaled was sitting in the garden under an apple tree, suddenly! , well... you should guess what happened, an

Gym 100952A&amp;&amp;2015 HIAST Collegiate Programming Contest A. Who is the winner?【字符串,暴力】

A. Who is the winner? time limit per test:1 second memory limit per test:64 megabytes input:standard input output:standard output A big marathon is held on Al-Maza Road, Damascus. Runners came from all over the world to run all the way along the road

codeforces gym 101164 K Cutting 字符串hash

题意:给你两个字符串a,b,不区分大小写,将b分成三段,重新拼接,问是否能得到A: 思路:暴力枚举两个断点,然后check的时候需要字符串hash,O(1)复杂度N*N: 题目链接:传送门 #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cmath> #include<string> #

Gym - 101908H Police Hypothesis (树链剖分+字符串哈希)

题意:有一棵树,树上每个结点上有一个字母,有两种操作: 1)询问树上两点u,v间有向路径上有多少个字母和某个固定的字符串相匹配 2)将结点u的字母修改为x 树剖+线段,暴力维护前缀和后缀哈希值(正反都要维护)以及区间内匹配的个数,合并两区间时判断一下跨过分界点的情况就行了.由于被匹配的字符串长度不超过100,所以最多只需维护长度为100的前缀/后缀. 但即使这样复杂度也足足有$O(100nlog^2n)$啊,这常数是得有多小才能过掉... 注意各种条件判断和细节处理,还有就是这题内存比较吃紧,使

【枚举】【字符串哈希】Gym - 101164K - Cutting

给你A B两个串,让你切B串两刀,问你能否把切开的三个串拼成A. 哈希显然. #include<cstdio> #include<cstring> using namespace std; typedef unsigned long long ull; const ull MOD1=2000000011; const ull MOD2=1000000007; const ull base1=10007; const ull base2=10009; int n; char a[10

字符串 || Gym 101653T Runes

给T个式子,其中有一个数字是?,让确定?代表哪个数字 负号,前导0,出现过的数字不能是? #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <queue> #include <algorithm> using namespace std; char s[33]; int

【字符串+BFS】Problem 7. James Bond

https://www.bnuoj.com/v3/external/gym/101241.pdf [题意] 给定n个字符串,大小写敏感 定义一个操作:选择任意m个串首尾相连组成一个新串 问是否存在一个这样的串s,s可以由不同的串首尾相连得到 最多100个字符串,所有字符串的总长度不超过5000 [样例解释] aB5可以由a+B5得到,也可以由aB+5得到,所以输出YES [思路] 首先一定是在100个选择2个串a,b,a是b的前缀 然后a和b的前缀可以消去,我们想知道b剩下的右半部分是哪一个串的