大鹏

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 

 

 

 参考答案

 1 ############################
 2 while True:
 3     try:
 4         s = input().lower()
 5         str1 = input().lower()
 6         s2 = []
 7 
 8         for a in range(len(s)):
 9             if s[a] not in str1:
10                 s2.append(s[a])
11 
12         if len(s2) != 0:
13             print('false')
14         else:
15             print('true')
16 
17     except:
18         break
19 ########################################################
20 
21 while True:
22     try:
23         S, T = input(), input()
24         if set(S) & set(T) == set(S):
25             print('true')
26         else:
27             print('false')
28     except:
29         break
30 ########################################################
31 while True:
32     try:
33         S, T = input(), input()
34         if set(S) & set(T) == set(S):
35             print('true')
36         else:
37             print('false')
38     except:
39         break
40 ########################################################
41 
42 while True:
43     try:
44         short_str = input()
45         long_str = input()
46         for t in short_str:
47             if long_str.count(t)==0:
48                 print("false")
49                 break
50         else:
51             print("true")
52     except:
53         break
54 
55 
56 ########################################################
57 def judge(s1,s2):
58     for i in s1:
59         if not i in s2:
60             return 'false'
61     return 'true'
62 while 1:
63     try:
64         print(judge(input(),input()))
65     except:
66         break
67 
68 ########################################################
69 
70 while True:
71     try:
72         a = list(input())
73         b = list(input())
74         len_a = len(a)
75         len_b = len(b)
76         if(len_a > len_b): #保证a始终是短的字符串
77             c = a
78             a = b
79             b = c
80             c = len_a
81             len_a = len_b
82             len_b = c
83         k = 0
84         flag = 0
85         for i in range(len_a):
86             for j in range(len_b):
87                 if(a[i] == b[j]): #若a的字符在b中出现
88                     flag += 1 #flag + 1
89                     break
90         if(flag == len_a): #若都出现
91             print('true')
92         else:
93             print('false')
94     except:
95         break
View Code

 

 

 

 

 

 

 

 参考答案

  1 while True:
  2     try:
  3         m, n = map(int, input().split())
  4         if 0 <= m <= 9 and 0 <= n <= 9:
  5             print(0)
  6         else:
  7             print(-1)
  8 
  9         x1, y1, x2, y2 = map(int, input().split())
 10         if 0 <= x1 <= m - 1 and 0 <= x2 <= m - 1 and 0 <= y1 <= n - 1 and 0 <= y2 <= n - 1:
 11             print(0)
 12         else:
 13             print(-1)
 14 
 15         x = int(input())
 16         if 0 <= x <= m - 1 and m + 1 <= 9:
 17             print(0)
 18         else:
 19             print(-1)
 20         y = int(input())
 21         if 0 <= y <= n - 1 and n + 1 <= 9:
 22             print(0)
 23         else:
 24             print(-1)
 25         x, y = map(int, input().split())
 26         if 0 <= x <= 9 and 0 <= y <= 9 and 0 <= x <= m - 1 and 0 <= y <= n - 1:
 27             print(0)
 28         else:
 29             print(-1)
 30     except:
 31         break
 32 
 33 #####################################################
 34 def create_table(x,y):
 35     if 0 < x <= 9 and 0 < y <= 9:
 36         global mytable
 37         mytable = [[i + j for j in range(y)] for i in range(x)]
 38         print('0')
 39     else:
 40         print('-1')
 41 
 42 def func(x,a):
 43     return True if x in range(a) else False
 44 
 45 def exchange_value(x1,y1,x2,y2):
 46     if all(map(func,[x1,x2],[a,a])) and all(map(func,[y1,y2],[b,b])):
 47         mytable[x1][y1],mytable[x2][y2] = mytable[x2][y2],mytable[x1][y1]
 48         print('0')
 49     else:
 50         print('-1')
 51 
 52 def add_row(x):
 53     if func(x,a) and a + 1 <= 9:
 54         mytable.insert(x-1, [j for j in range(b)])
 55         mytable.pop()
 56         print('0')
 57     else:
 58         print('-1')
 59 
 60 def add_colomn(y):
 61     if func(y,b) and b + 1 <= 9:
 62         for i in range(a):
 63             mytable[i].insert(y-1, i)
 64             mytable[i].pop()
 65         print('0')
 66     else:
 67         print('-1')
 68 
 69 def check_cell(x,y):
 70     if func(x,a) and func(y,b):
 71         print('0')
 72     else:
 73         print('-1')
 74 
 75 while True:
 76     try:
 77         a,b = map(int,input().split())
 78         create_table(a, b)
 79         c,d,e,f = map(int,input().split())
 80         exchange_value(c,d,e,f)
 81         g = int(input())
 82         add_row(g)
 83         h = int(input())
 84         add_colomn(h)
 85         k,l = map(int,input().split())
 86         check_cell(k,l)
 87     except:
 88         break
 89 
 90 
 91 ######################################################
 92 
 93 m,n = list(map(int,input().split()))
 94 
 95 x = int(input()) #3、输入要插入的行数
 96 y = int(input()) # 4、输入要插入的行数
 97 # print(m,n)
 98 s =m*n
 99 
100 #1、初始化表格
101 if 1<=m and n<10:
102     print(0)
103 else:
104     print(-1)
105 
106 # #2、交换数字
107 # x1, y1, x2, y2 =list(map(int,input().split()))
108 #
109 # if x1 >m or y1>n or x2 >m or y2>n :
110 #     print(-1)
111 
112 
113 
114 
115 if 1<=x+m<10:
116     print(0)
117     s = m * n
118 else:
119     print(-1)
120 
121 if 1 <= y + n < 10:
122     print(0)
123     s = m * n
124 else:
125     print(-1)
126 # print(s)
127 
128 if  (0<x<=m and  1<=x+m<10)  and (0<y<=n and  1<=y+n<10):
129     print(0)
130 elif x>m or y>n:
131     print(-1)
View Code

 

 

 

 参考答案

 1 s = input()
 2 print(s)
 3 L1 = ['A', 'B', 'C', 'D', 'E', 'F', 'G',....]
 4 L2 = []
 5 
 6 for a in range(len(s)):
 7     if s[a] in L1:
 8         L2.append(s[a])
 9 print(len(L2))
10 
11 ###########################################
12 ##法二 用字符串的比大小!>='A' <='Z'
13 while True:
14     try:
15         s = input()
16         L2 = []
17         for a in range(len(s)):
18             if 'A' <= s[a] <= 'Z':
19                 L2.append(s[a])
20         print(len(L2))
21     except:
22         break
23 ###########################################
24 
25 while True:
26 
27     try:
28         s=input()
29         res=0
30         for i in s:
31             if i.isupper():
32                 res+=1
33         print(res)
34     except:
35         break
36 
37 ###########################################
38 #法三:用ord() ASCll表 <91 and ord(i)>64
39 while True:
40     try:
41         s = input()
42         n=0
43         for i in s:
44             if ord(i)<91 and ord(i)>64:
45                 n=n+1
46         print(n)
47     except:
48         break
View Code

 

 

 

 参考答案

  1 while True:
  2     try:
  3         s = input()
  4         res = []
  5 
  6         for i in range(len(s)):
  7             for j in range(i + 1, len(s) + 1):
  8                 if s[i:j] == s[i:j][::-1]:
  9                     res.append(j - i)
 10         if res != '':
 11             print(max(res))
 12     except:
 13         break
 14 
 15 
 16 
 17 
 18 while True:
 19     try:
 20         s = input()  # 输入
 21         len_s = len(s)
 22         result = 0  # result用于记录目前最长的子串长度,初始化为0
 23         for n in range(len):  # 从第一个字符的位置开始检查
 24             max_len = result + 1  # max_len代表当前检查字符串的长度
 25         while n + max_len <= len:  # 代表搜索完以第n+1个字符串开头的所有字符串
 26             if s[n:n + max_len] == s[n:n + max_len][::-1]:  # 如果满足是回文字符串
 27                 result = max_len  # 则此时最大的字符串长度变为max_len
 28             max_len += 1  # 每次增加字符串的长度1
 29         if result != 0:
 30             print(result)
 31     except:
 32         break
 33 
 34 
 35 
 36 
 37 
 38 
 39 
 40 l = input()
 41 Max = 0
 42 for i in range(len(l)):
 43     for j in range(i,len(l)):
 44         if l[i:j+1] == l[i:j+1][::-1] and j-i+1 > Max:
 45             Max = j-i+1
 46         else:
 47             continue
 48 print(Max)
 49 
 50 
 51 while True:
 52     try:
 53         s = input()
 54         n = len(s)
 55         if n < 2:
 56             print(n)
 57         else:
 58             dp = [[False] * n for _ in range(n)]
 59             for i in range(n):
 60                 dp[i][i] = True
 61             Max = 1
 62             for l in range(2, n+1):
 63                 for i in range(n):
 64                     j = i + l - 1
 65                     if j >= n:
 66                         break
 67                     if s[i] != s[j]:
 68                         dp[i][j] = False
 69                     else:
 70                         if j - i < 3:
 71                             dp[i][j] = True
 72                         else:
 73                             dp[i][j] = dp[i+1][j-1]
 74                     if dp[i][j] and j + 1 - i > Max:
 75                         Max = j + 1 - i
 76             print(Max)
 77     except:
 78         break
 79 
 80 while True:
 81     try:
 82         s = input()
 83         n = len(s)
 84         if n < 2:
 85             print(n)
 86 
 87         max_len = 1
 88         begin = 0
 89         # dp[i][j] 表示 s[i..j] 是否是回文串
 90         dp = [[False] * n for _ in range(n)]
 91         for i in range(n):
 92             dp[i][i] = True
 93 
 94         # 递推开始
 95         # 先枚举子串长度
 96         for L in range(2, n + 1):
 97             # 枚举左边界,左边界的上限设置可以宽松一些
 98             for i in range(n):
 99                 # 由 L 和 i 可以确定右边界,即 j - i + 1 = L 得
100                 j = L + i - 1
101                 # 如果右边界越界,就可以退出当前循环
102                 if j >= n:
103                     break
104 
105                 if s[i] != s[j]:
106                     dp[i][j] = False
107                 else:
108                     if j - i < 3:
109                         dp[i][j] = True
110                     else:
111                         dp[i][j] = dp[i + 1][j - 1]
112 
113                 # 只要 dp[i][L] == true 成立,就表示子串 s[i..L] 是回文,此时记录回文长度和起始位置
114                 if dp[i][j] and j - i + 1 > max_len:
115                     max_len = j - i + 1
116         print(max_len)
117     except:
118         break
View Code

 

 

 

 参考答案

 1 while True:
 2     try:
 3         num = int(input())
 4         #print(bin(num))
 5         s = list(set(str(bin(num))[2:].split('0')))
 6         #print(s)
 7 
 8         print(len(max(s)))
 9     except:
10         break
11 
12 
13 while True:
14     try:
15         x = int(input())
16         byte_x = bin(x)[2:]
17         list1 = sorted(list(set(byte_x.split('0'))), key = lambda x: len(x), reverse=True)
18         print(len(list1[0]))
19     except:
20         break
21 
22 while True:
23 
24     try:
25         s = input()
26         ## 数字格式-> 二元格式 -> 清除非数字 -> 零作为间隔符号
27         string = bin(int(s)).replace("0b", "").split("0")
28         longest = 0
29         for i in string:
30             count = i.count("1")
31             if count > longest:
32                 longest = count
33         print(longest)
34     except:
35         break
36 
37 
38 while True:
39     try:
40         n = int(input())
41         s = bin(n).replace('0b', '')
42         s = (8 - len(s)) * '0' + s
43         Max, count = 1, 1
44         i = s.index('1')
45         while i < len(s) - 1:
46             for j in range(i+1, len(s)):
47                 if s[j] == '1':
48                     count += 1
49                 else:
50                     break
51                 Max = max(Max, count)
52             if '1' in s[j+1:]:
53                 i = s.index('1', j+1)
54                 count = 1
55             else:
56                 break
57         print(Max)
58     except:
59         break
60 
61 
62 ####################################################
63 def get_ans(s):
64     ans=[]
65     res=0
66     mark=str(bin(int(s)))
67     for i in mark:
68         if i=='1':
69             res+=1
70             ans.append(res)
71         if i=='0':
72             ans.append(res)
73             res=0
74     return max(ans)
75 
76 if __name__=='__main__':
77     import sys
78     lines = []
79     while True:
80         line = sys.stdin.readline().strip()
81         if line == "":
82             break
83         lines.append(line)
84     for item in lines:
85         print(get_ans(item))
86 ####################################################
87 
88 while True:
89     try:
90         n=str(bin(int(input())))
91         li=re.findall(r'1+', n)
92         q=max(map(len, li))
93         print(q)
94     except:
95         break
View Code

 

 

 

 

 

 

 

 

 

 参考答案

 1 # s = input()  # 输入一个秘密
 2 #
 3 # print(s.isalpha())
 4 #
 5 # print(s.isupper())
 6 # print(s.islower())
 7 
 8 while True:
 9     try:
10 
11         import re
12 
13 
14         def fun(pwd):
15             score = 0
16             #     规则一、密码长度:
17             if len(pwd) <= 4:
18                 score += 5
19             elif 5<=len(pwd) <= 7:
20                 score += 10
21             else:
22                 score += 25
23             #     规则二、字母:
24             if re.findall('[a-z]', pwd) and re.findall('[A-Z]', pwd):
25                 score += 20
26             elif re.findall('[a-z]', pwd) or re.findall('[A-Z]', pwd):
27                 score += 10
28             else:
29                 score += 0
30             #     规则三、数字:
31             #count = len(''.join(re.findall(r'\d+', pwd)))
32             count = len(re.findall(r'\d+', pwd))
33             if count == 0:
34                 score += 0
35             elif count == 1:
36                 score += 10
37             else:
38                 score += 20
39             #     规则四、符号:
40             count = len(''.join(re.findall('[^0-9a-zA-Z]', pwd)))
41             if count == 0:
42                 score += 0
43             elif count == 1:
44                 score += 10
45             else:
46                 score += 25
47             #     规则五、奖励:
48             if re.findall('[a-z]', pwd) and re.findall('[A-Z]', pwd) and re.findall(r'\d+', pwd) and re.findall(
49                     '[^0-9a-zA-Z]', pwd):
50                 score += 5
51             elif re.findall('[a-zA-Z]', pwd) and re.findall(r'\d+', pwd) and re.findall('[^0-9a-zA-Z]', pwd):
52                 score += 3
53             elif re.findall('[a-zA-Z]', pwd) and re.findall(r'\d+', pwd):
54                 score += 2
55             #     判断等级
56             if score >= 90:
57                 print('VERY_SECURE')
58             elif score >= 80:
59                 print('SECURE')
60             elif score >= 70:
61                 print('VERY_STRONG')
62             elif score >= 60:
63                 print('STRONG')
64             elif score >= 50:
65                 print('AVERAGE')
66             elif score >= 25:
67                 print('WEAK')
68             elif score >= 0:
69                 print('VERY_WEAK')
70 
71 
72         pwd = input()
73         fun(pwd)
74     except:
75         break
View Code

 参考答案二,用字符串方式,很经典

  1 def len_s(z):        #密码长度得分
  2     a = len(z)
  3     if 0 < a <= 4:
  4         return 5
  5     elif 5 <= a <=7:
  6         return 10
  7     elif a >= 8:
  8         return 25
  9     else:
 10         return 0
 11 
 12 def low_s(z):        #字母大小写得分
 13     b = str(z)
 14     sb = 0 #小写字母个数
 15     bb = 0 #大写字母个数
 16     for i in b:
 17         if i.islower():
 18             sb += 1
 19         if i.isupper():
 20             bb += 1
 21     if (sb != 0 and bb == 0) or (sb == 0 and bb != 0):
 22         return 10
 23     if sb != 0 and bb != 0:
 24         return 20
 25     else:
 26         return 0
 27 
 28 def num_s(z):        #数字个数得分
 29     c = str(z)
 30     nc = 0
 31     for i in c:
 32         if i.isdigit():
 33             nc += 1
 34     if nc == 1:
 35         return 10
 36     if nc > 1:
 37         return 20
 38     else:
 39         return 0
 40 
 41 def symbol_s(z):        #符号存在得分
 42     d = str(z)
 43     nd = 0
 44     symbol = "!\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~"
 45     for i in d:
 46         if i in symbol:
 47             nd += 1
 48     if nd == 1:
 49         return 10
 50     if nd > 1:
 51         return 25
 52     else:
 53         return 0
 54 
 55 def get_x(z):        #奖励得分
 56     e = str(z)
 57     se = 0
 58     le = 0
 59     for i in e:
 60         if i.islower():
 61             se += 1
 62         if i.isupper():
 63             le += 1
 64     if ((se != 0 and le == 0) or (le != 0 and se == 0)) and num_s(e) != 0:
 65         return 2
 66     if ((se != 0 and le == 0) or (le != 0 and se == 0)) and num_s(e) != 0 and symbol_s(e)!= 0:
 67         return 3
 68     if (se != 0 and le != 0) and num_s(e) != 0 and symbol_s(e)!= 0:
 69         return 5
 70     else:
 71         return 0
 72 
 73 while True:
 74     try:
 75         f = str(input())
 76         score = len_s(f) + low_s(f) + num_s(f) + symbol_s(f) + get_x(f)
 77         if score >= 90:
 78             print("VERY_SECURE")
 79         if 80 <= score < 90:
 80             print("SECURE")
 81         if 70 <= score < 80:
 82             print("VERY_STRONG")
 83         if 60 <= score < 70:
 84             print("STRONG")
 85         if 50 <= score < 60:
 86             print("AVERAGE")
 87         if 25 <= score < 50:
 88             print("WEAK")
 89         if 0 <= score < 25:
 90             print("VERY_WEAK")
 91     except:
 92         break
 93 
 94 
 95 
 96 ##########################################
 97 
 98 while True:
 99     try:
100         pwd_str = input()
101         output_num = 0
102         # 一、密码长度:
103         if len(pwd_str) <= 4:
104             output_num += 5
105         elif 5 <= len(pwd_str) <= 7:
106             output_num += 10
107         elif len(pwd_str) >= 8:
108             output_num += 25
109         islower_num = 0
110         isupper_num = 0
111         isdigit_num = 0
112         isother_num = 0
113         for word in pwd_str:
114             if word.islower():
115                 islower_num += 1
116             elif word.isupper():
117                 isupper_num += 1
118             elif word.isdigit():
119                 isdigit_num += 1
120             else:
121                 isother_num += 1
122         # 二、字母:
123         if islower_num == 0 and isupper_num == 0:
124             output_num += 0
125         elif (islower_num != 0 and isupper_num == 0) or (islower_num == 0 and isupper_num != 0):
126             output_num += 10
127         elif islower_num != 0 and isupper_num != 0:
128             output_num += 20
129         # 三、数字:
130         if isdigit_num == 0:
131             output_num += 0
132         elif isdigit_num == 1:
133             output_num += 10
134         elif isdigit_num > 1:
135             output_num += 20
136         # 四、符号:
137         if isother_num == 0:
138             output_num += 0
139         elif isother_num == 1:
140             output_num += 10
141         elif isother_num > 1:
142             output_num += 25
143         # 五、奖励:
144         if islower_num != 0 and isupper_num != 0 and isdigit_num != 0 and isother_num != 0:
145             output_num += 5
146         elif (islower_num != 0 or isupper_num != 0) and isdigit_num != 0 and isother_num != 0:
147             output_num += 3
148         elif (islower_num != 0 or isupper_num != 0) and isdigit_num != 0:
149             output_num += 2
150 
151         if output_num >= 90:
152             print("VERY_SECURE")
153         elif output_num >= 80:
154             print("SECURE")
155         elif output_num >= 70:
156             print("VERY_STRONG")
157         elif output_num >= 60:
158             print("STRONG")
159         elif output_num >= 50:
160             print("AVERAGE")
161         elif output_num >= 25:
162             print("WEAK")
163         elif output_num >= 0:
164             print("VERY_WEAK")
165     except:
166         break
View Code

 

正则表达式,参考

Python之re模块

 

posted on 2022-04-06 22:00  pf42280  阅读(62)  评论(0编辑  收藏  举报