文章目录
密码输入检测
- 给定用户密码的input输入流,< 表示退格,清除前一个字符;
- 输出最终得到的密码,并判断是否满足如下密码安全要求
- 长度>=8
- 至少包含一个大写字母
- 至少包含一个小写字母
- 至少包含一个数字
- 至少包含一个(字母、数字)以外的非空白特殊字符
- 空串退格后仍为空串,且输入不含空白字符
输入描述:
输入一行字符串
输出描述:
输出实际的密码字符串,是否满足安全要求,两者以逗号分隔
示例1
输入:
ABC<c89%000<
输出:
ABc89%00,true
思路:
简单字符串处理
- 解析真实密码;
- 验证是否满足安全要求
python
def is_valid(s):
global conditions
conditions[0] = len(s) >= 8
for c in s:
# 对字符的判断
if ord(c) >= 65 and ord(c) <= 90:
conditions[1] = True
elif ord(c) >= 97 and ord(c) <= 122:
conditions[2] = True
elif ord(c) >= 48 and ord(c) <= 57:
conditions[3] = True
elif c != " ":
conditions[4] = True
return all(conditions)
# 输入
s = input().strip()
# 退格后的字符串
char_list = []
conditions = [False for _ in range(5)]
for c in s:
if c != "<":
char_list.append(c)
else:
if char_list:
char_list.pop()
# 密码是否满足安全要求
r_str = "".join(char_list)
if is_valid(r_str):
print(f"{r_str},true")
else:
print(f"{r_str},false")