zoukankan      html  css  js  c++  java
  • Login Verification CodeForces

    When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.

    Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins s and t are considered similar if we can transform s to t via a sequence of operations of the following types:

    • transform lowercase letters to uppercase and vice versa;
    • change letter «O» (uppercase latin letter) to digit «0» and vice versa;
    • change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other.

    For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not.

    You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones.

    Input

    The first line contains a non-empty string s consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50  — the login itself.

    The second line contains a single integer n (1 ≤ n ≤ 1 000) — the number of existing logins.

    The next n lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar.

    Output

    Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.

    Otherwise print «No» (without quotes).

    Examples

    Input
    1_wat
    2
    2_wat
    wat_1
    Output
    Yes
    Input
    000
    3
    00
    ooA
    oOo
    Output
    No
    Input
    _i_
    3
    __i_
    _1_
    I
    Output
    No
    Input
    La0
    3
    2a0
    La1
    1a0
    Output
    No
    Input
    abc
    1
    aBc
    Output
    No
    Input
    0Lil
    2
    LIL0
    0Ril
    Output
    Yes

    Note

    In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.

    In the third sample case the new login is similar with the second one.

    题意:

    给你一个字符串str,和n个其他字符串x,

    如果这n个字符串中有任意一个可以通过题目给的3种变换操作变成和str一样的字符串,就输出No,否则输出Yes。

    思路:

    把规则统一即可。

    即把所有的字符串和str都执行以下操作。

    ,所有的大写字符变为小写字符。

    所有的L,I,i,l,都变为1

    所有的o,O,都变为0,

    然后对于每一个字符串都直接比较和str是否相等,相等就是No即可。

    注意细节被出错误即可。

    见代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <queue>
    #include <stack>
    #include <map>
    #include <set>
    #include <vector>
    #include <iomanip>
    #define ALL(x) (x).begin(), (x).end()
    #define rt return
    #define dll(x) scanf("%I64d",&x)
    #define xll(x) printf("%I64d
    ",x)
    #define sz(a) int(a.size())
    #define all(a) a.begin(), a.end()
    #define rep(i,x,n) for(int i=x;i<n;i++)
    #define repd(i,x,n) for(int i=x;i<=n;i++)
    #define pii pair<int,int>
    #define pll pair<long long ,long long>
    #define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
    #define MS0(X) memset((X), 0, sizeof((X)))
    #define MSC0(X) memset((X), '', sizeof((X)))
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define eps 1e-6
    #define gg(x) getInt(&x)
    #define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
    using namespace std;
    typedef long long ll;
    ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
    ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
    ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2)ans = ans * a % MOD; a = a * a % MOD; b /= 2;} return ans;}
    inline void getInt(int* p);
    const int maxn = 1000010;
    const int inf = 0x3f3f3f3f;
    /*** TEMPLATE CODE * * STARTS HERE ***/
    
    int main()
    {
        //freopen("D:\common_text\code_stream\in.txt","r",stdin);
        //freopen("D:\common_text\code_stream\out.txt","w",stdout);
    
        string str;
        gbtb;
        cin >> str;
        int n;
        cin >> n;
        int isok = 0;
        string temp;
        int len = str.length();
        rep(j, 0, len)
        {
            if (str[j] == 'O')
            {
                str[j] = '0';
            } else if (str[j] == 'o')
            {
                str[j] = '0';
            } else if (str[j] == 'l')
            {
                str[j] = '1';
            } else if (str[j] == 'L')
            {
                str[j] = '1';
            } else if (str[j] == 'i')
            {
                str[j] = '1';
            } else if (str[j] == 'I')
            {
                str[j] = '1';
            } else if (str[j] >= 'A' && str[j] <= 'Z')
            {
                str[j] += ('a' - 'A');
            }
        }
        repd(i, 1, n)
        {
            cin >> temp;
            int tlen = temp.length();
            if (tlen == len)
            {
                rep(j, 0, tlen)
                {
                    if (temp[j] == 'O')
                    {
                        temp[j] = '0';
                    } else if (temp[j] == 'o')
                    {
                        temp[j] = '0';
                    } else if (temp[j] == 'l')
                    {
                        temp[j] = '1';
                    } else if (temp[j] == 'L')
                    {
                        temp[j] = '1';
                    } else if (temp[j] == 'i')
                    {
                        temp[j] = '1';
                    } else if (temp[j] == 'I')
                    {
                        temp[j] = '1';
                    } else if (temp[j] >= 'A' && temp[j] <= 'Z')
                    {
                        temp[j] += ('a' - 'A');
                    }
                }
                if (temp == str)
                {
                    isok = 1;
                }
            }
        }
    
        if (!isok)
        {
            cout << "Yes" << endl;
        } else
        {
            cout << "No" << endl;
        }
        return 0;
    }
    
    inline void getInt(int* p) {
        char ch;
        do {
            ch = getchar();
        } while (ch == ' ' || ch == '
    ');
        if (ch == '-') {
            *p = -(getchar() - '0');
            while ((ch = getchar()) >= '0' && ch <= '9') {
                *p = *p * 10 - ch + '0';
            }
        }
        else {
            *p = ch - '0';
            while ((ch = getchar()) >= '0' && ch <= '9') {
                *p = *p * 10 + ch - '0';
            }
        }
    }
    本博客为本人原创,如需转载,请必须声明博客的源地址。 本人博客地址为:www.cnblogs.com/qieqiemin/ 希望所写的文章对您有帮助。
  • 相关阅读:
    iOS开发 -------- AFNetworking使用中遇到的小问题
    iOS开发 -------- AFNetworking实现简单的断点下载
    规则引擎-BRMS在企业开发中的应用
    MySQL系列教程(四)
    MySQL系列教程(三)
    MySQL系列教程(二)
    MySQL系列教程(一)
    OWASP Top 10十大风险 – 10个最重大的Web应用风险与攻防
    【事务】<查询不到同一调用方法其它事务提交的更新>解决方案
    iOS控制反转(IoC)与依赖注入(DI)的实现
  • 原文地址:https://www.cnblogs.com/qieqiemin/p/10735837.html
Copyright © 2011-2022 走看看