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.
OutputPrint yes if the entered password should be accepted according to Islam, otherwise print no.
Examples InputAgentMahoneOutput
IslamIsMahone
no
Input
ofmahoneOutput
ofmahome
yes
Input
algorithmsOutput
algorthms
yes
Input
MahoneOutput
mahonE
no
题目看错了!!!!错误1:user’s password(正确密码) 和 the entered password(输入密码需要判断). 理解反了
错误2 : a mistake with only one character (either replaced it with a wrong character or dropped it)
只有一个字符(用错误的字符替换或丢弃) 我自以为是的认为输入密码比正确密码只是多了一个字符(其他部分一样)也算正确 例如:asdasdasd asdasdasda 这实际上是错误的。。。
#include <iostream>#include<cstdio>#include<string>#include<cstring>#include<algorithm>#include <stdio.h>#include <string.h>using namespace std;char a[1000009] , b[1000009] ;int main(){ char a[200] , b[200] ; int ans = 0 ; while(~scanf("%s%s" , a , b)) { int len1 = strlen(a) , len2 = strlen(b); if(len1 >= 8) { if(len1 > len2 && len1 - len2 == 1) { int j = 0 ; for(int i = 0 ; i < len2 ; i++) { if(a[j++] != b[i]) // 如果不同,就让b字符串停留下,a正常走,a更长 { ans++ ; i-- ; } if(ans >= 2) break ; } if(ans <= 1) cout << "yes" << endl ; else cout << "no" << endl ; } else if(len1 < len2) // 一开始理解错误的地方 { cout << "no" << endl ; } else if(len1 == len2) { for(int i = 0 ; i < len1 ; i++) { if(a[i] != b[i]) { ans++ ; } } if(ans <= 1) cout << "yes" << endl ; else cout << "no" << endl ; } else cout << "no" << endl ; } else { if(len1 == len2) { for(int i = 0 ; i < len2 ; i++) { if(a[i] != b[i]) { ans++ ; } } if(ans == 0) cout << "yes" << endl ; else cout << "no" <<endl ; } else cout << "no" << endl ; } memset(a , ‘\0‘ , sizeof(a)); memset(b , ‘\0‘ , sizeof(b)); ans = 0 ; } return 0;}