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 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

时间: 2024-12-14 19:48:37

UESTC 2016 Summer Training #1 Div.2 E - Accepted Passwords 讨论的相关文章

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 #5 Div.2(未完待续)

A #include <cstdio> #include <cstring> #include <vector> #define MAXN 100005 #define mem(a) memset(a, 0, sizeof(a)) using namespace std; int TreeArray[MAXN], Left[MAXN], Right[MAXN], Fork[MAXN]; typedef vector<int> Ve; vector<Ve

UESTC 2016 Summer Training #2 Div.2 A dp、递推、多阶段问题

A - A Time Limit:336MS     Memory Limit:1572864KB     64bit IO Format:%lld & %llu Submit Status Practice SPOJ AMR11A Description Thanks a lot for helping Harry Potter in finding the Sorcerer's Stone of Immortality in October. Did we not tell you that

UESTC 2016 Summer Training #1 Div.2 F - Mission in Amman (A) 动态维护(刷新:--、++)

F - Mission in Amman (A) Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100989F Description standard input/output You must have heard about Agent Mahone! Dr. Ibrahim hired him to catch the che

UESTC 2016 Summer Training #1 Div.2 L - Plus or Minus (A) dfs

L - Plus or Minus (A) Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100989L Description standard input/output AbdelKader enjoys math. He feels very frustrated whenever he sees an incorrect eq

UESTC 2016 Summer Training #1 Div.2 H - Queue (A) 贪心

H - Queue (A) Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100989H Description standard input/output After the data structures exam, students lined up in the cafeteria to have a drink and ch

UESTC 2016 Summer Training #2 Div.2 E 分解质因素(除了以后剩下的可能也是个素数)

E - E Time Limit:3000MS     Memory Limit:1572864KB     64bit IO Format:%lld & %llu Submit Status Practice SPOJ AMR11E Description Arithmancy is Draco Malfoy's favorite subject, but what spoils it for him is that Hermione Granger is in his class, and

UESTC 2014 Summer Training #18 Div.2

A.UVALive 6661 题意从1~N中选k个数,和为s的方案数 第一眼搜索,估计错状态量,又去yydp...浪费大量时间 数据很小的,状态数都不会超过2^N...直接dfs就过了 //state二进制表示选取的数 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; const int maxn = 200; in

UESTC 2014 Summer Training #3 Div.2

(更新中) A:ZOJ 3611 BFS+状态压缩 [题意]:给定一张n*m的图,图上每个点有如下情况:L,R,D,U:代表在该点上只能往它已经给定的方向前进.#,W:不能走到该点.$:走到该点,可以花两分钟得到一分值,然后可以从该点向任意方向走.0:走到该点后可以向任意方向走.然后给你起点和终点坐标,问是否能从起点走到终点,如果能,求出可获得的最大分值以及与之对应达到该最大分值所需的的最小时间花 费.(其中起点和终点坐标可以相同)[知识点]:BFS+状态压缩[题解]:我觉得超级棒的题!真心感觉