标签:
Description
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
AgentMahone IslamIsMahone
no
ofmahone ofmahome
yes
algorithms algorthms
yes
Mahone mahonE
no
Source
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=121539#problem/E
My Solution
看清楚题目就好了 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).
然后讨论一下就好了
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn = 106; char pas[maxn], w[maxn]; int main() { #ifdef LOCAL freopen("a.txt", "r", stdin); //freopen("b.txt", "w", stdout); int T = 4; while(T--){ #endif // LOCAL int cnt = 0; scanf("%s", pas); scanf("%s", w); int sz1 = strlen(pas), sz2 = strlen(w); if(sz1 == sz2){ for(int i = 0; i < sz1; i++){ if(pas[i] != w[i]) cnt++; } if(sz1 >= 8 && cnt <= 1) printf("yes"); else{ if(cnt == 0) printf("yes"); else printf("no"); } } else{ //!!!!! (┬_┬) 前面漏了少一个也是在password >= 8 时才行的, 白白WA了2发 if(sz1 < 8) printf("no"); else{ if(sz1 == sz2 + 1){ for(int i = 0; i < sz1; i++){ if(cnt != 0){ if(pas[i] == w[i-1]) ; else {printf("no"); cnt = -1; break;} } else{ if(pas[i] == w[i]) ; else{ if(cnt == 0) {cnt++;} else {printf("no"); cnt = -1; break;} } } } if(cnt != -1) printf("yes"); } else printf("no"); }} #ifdef LOCAL printf("\n"); } #endif // LOCAL return 0; }
Thank you!
------from ProLights
UESTC 2016 Summer Training #1 Div.2 E - Accepted Passwords 讨论
标签:
原文地址:http://blog.csdn.net/prolightsfxjh/article/details/51892465