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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值