HJ20 密码验证合格程序

摘要
Title: HJ20 密码验证合格程序
Tag: 字符串
Memory Limit: 64 MB
Time Limit: 1000 ms

Powered by:NEFU AB-IN

Link

HJ20 密码验证合格程序

  • 题意

    密码要求: 1.长度超过8位 2.包括大小写字母.数字.其它符号,以上四种至少三种 3.不能有长度大于2的包含公共元素的子串重复 (注:其他符号不含空格或换行) 数据范围:输入的字符串长度满足

  • 思路

    加入字典判断是否存在相同的字符串

  • 代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    #include <bits/stdc++.h>
    #include <cctype>
    #include <unordered_map>
    using namespace std;
    #define int long long
    #undef int

    #define SZ(X) ((int)(X).size())
    #define ALL(X) (X).begin(), (X).end()
    #define IOS \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr); \
    cout.tie(nullptr)
    #define DEBUG(X) cout << #X << ": " << X << '\n'

    const int M = 70, N = 4e4 + 10, INF = 0x3f3f3f3f;


    bool check(string s) {
    if (SZ(s) <= 8) return false;
    int a = 0, b = 0, c = 0, d = 0;

    unordered_map<string , int> vis;
    for (int i = 0; i < SZ(s); ++i) {
    if (isupper(s[i])) a = 1;
    else if (islower(s[i])) b = 1;
    else if (isdigit(s[i])) c = 1;
    else d = 1;

    if(i + 2 < SZ(s) && vis[s.substr(i, 3)]){
    return false;
    }
    vis[s.substr(i, 3)] = 1;
    }
    return a + b + c + d >= 3;
    }



    signed main() {
    IOS;
    string s;
    while (cin >> s) {
    if (check(s)) cout << "OK\n";
    else cout << "NG\n";
    }

    return 0;
    }
使用搜索:谷歌必应百度