码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-07-13 17:13:48      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:

E - Accepted Passwords
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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
AgentMahone
IslamIsMahone
Output
no
Input
ofmahone
ofmahome
Output
yes
Input
algorithms
algorthms
Output
yes
Input
Mahone
mahonE
Output
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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!