首页 > 9.8软开,双AC
头像
VinceZzz
编辑于 2020-09-08 19:45
+ 关注

9.8软开,双AC

import string
class Solution:
    def crypto(self, passwords):
        for password in passwords:
            if len(password) < 8&nbs***bsp;len(password) > 120:
                print(1)
                continue
            if self.containsDigit(password) and self.containsLower(password) and self.containsUpper(password) and self.containsPunctuation(password):
                print(0)
            else:
                print(2)
        return
    
    def containsPunctuation(self, password):
        for p in string.punctuation:
            if p in password:
                return True
        return False
    
    def containsDigit(self, password):
        for p in string.digits:
            if p in password:
                return True
        return False
    
    def containsUpper(self, password):
        for p in string.ascii_uppercase:
            if p in password:
                return True
        return False
    
    def containsLower(self, password):
        for p in string.ascii_lowercase:
            if p in password:
                return True
        return False
    
if __name__ == "__main__":
    s = Solution()
    passwords = list(map(str, input().split(" ")))
    s.crypto(passwords)

class Solution:
    def wordSearch(self, mat, word):
        visited = []
        def dfs(mat, i, j, idx, visited):
            if idx == len(word):
                return True
            
            if 0 <= i-1 < len(mat) and (i-1, j) not in visited and mat[i-1][j] == word[idx]:
                visited.append((i-1, j))
                if dfs(mat, i-1, j, idx+1, visited):
                    return True
                visited.remove((i-1, j))
            
            if 0 <= i+1 < len(mat) and (i+1, j) not in visited and mat[i+1][j] == word[idx]:
                visited.append((i+1, j))
                if dfs(mat, i+1, j, idx+1, visited):
                    return True
                visited.remove((i+1, j))
            
            if 0 <= j-1 < len(mat[0]) and (i, j-1) not in visited and mat[i][j-1] == word[idx]:
                visited.append((i, j-1))
                if dfs(mat, i, j-1, idx+1, visited):
                    return True
                visited.remove((i, j-1))
            
            if 0 <= j+1 < len(mat[0]) and (i, j+1) not in visited and mat[i][j+1] == word[idx]:
                visited.append((i, j+1))
                if dfs(mat, i, j+1, idx+1, visited):
                    return True
                visited.remove((i, j+1))
            return False

        for i in range(len(mat)):
            for j in range(len(mat[0])):
                if mat[i][j] == word[0] and dfs(mat, i, j, 1, [(i,j)]):
                    return True
        return False
    
if __name__ == "__main__":
    s = Solution()
    word = str(input())
    mat = [['A','B','C','E'],
           ['S','F','C','S'],
           ['A','D','E','E']]
    if not word:
        print("false")
    else:
        if s.wordSearch(mat, word):
            print("true")
        else:
            print("false")

全部评论

(0) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

近期热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐