刷题-HJ20 密码验证合格程序
#include 
#include 
#include 

bool threeCharacters(char *str, int len) {
    int a = 0, b = 0, c = 0, d = 0;
    for (int i = 0; i < len; i++) {
        if (str[i] >= '0' && str[i] <= '9') {
            a = 1;
        }
        else if (str[i] >= 'a' && str[i] <= 'z') {
            b = 1;
        }
        else if (str[i] >= 'A' && str[i] <= 'Z') {
            c = 1;
        }
        else {
            d = 1;
        }
        if (a + b + c + d > 2) {
            return true;
        }
    }
    return false;    
}

bool threeRepeat(char *str, int len) {
    int fast = 1, slow = 0, nums = 0;
    while (str[slow] != '\0') {
        if (str[fast++] == str[slow]) {
            for (int i = 1; i < 3; i++) {
                if (str[fast-1+i] == '\0') {
                    break;
                }
                else if (str[fast-1+i] == str[slow+i]) {
                    nums++;
                }
            }
            if (nums > 1) { 
                return false;
            }
            else {
                nums = 0;
            }
        }
        else if (str[fast] == '\0') {
            slow++;
            fast = slow + 1;
        }
    }
    return true;
}

int main() {
    char str[100] = {'\0'};
    while (gets(str)) {
        int len = strlen(str);
        if (len > 8 && threeCharacters(str, len) && threeRepeat(str, len)) {
            printf("OK\n");
        }
        else {
            printf("NG\n");
        }
    }
    return 0;
}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇