题解 | #密码验证合格程序#

密码验证合格程序

https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841

import Foundation

while let line = readLine() {
    let parts = line.split(separator: " ")
    let arr = Array(parts[0])
    if arr.count <= 8 {
        print("NG")
        continue
    }
    var small = 0
    var big = 0
    var num = 0
    var other = 0
    for i in 0 ... arr.count - 1 {
        var ch = arr[i]
        if ("0" ... "9").contains(ch) {
            num = num + 1
        } else if ("A" ... "Z").contains(ch) {
            big = big + 1
        } else if ("a" ... "z").contains(ch) {
            small =  small + 1
        } else {
            other = other + 1
        }
    }
    var count = 0
    if small > 0 {
        count = count + 1
    }
    if big > 0 {
        count = count + 1
    }
    if num > 0 {
        count = count + 1
    }
    if other > 0 {
        count = count + 1
    }
    
    if count < 3 {
        print("NG")
        continue
    }
    var ng = "OK"
    for i in 0 ... arr.count - 3 {
     var str = String(arr[i ... i+2])
     var res = parts[0].components(separatedBy: str)
        if res.count >= 3 {
            ng = "NG"
            break
        }
    }
    print(ng)
}

全部评论

相关推荐

08-27 12:02
已编辑
南京外国语学校 网络安全
再来一遍:实则劝各位不要all in华子,不要相信华为hr
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务