|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
0. 请用已学过的知识编写程序,找出小甲鱼藏在下边这个长字符串中的密码,密码的埋藏点符合一下规律:
(1) 每位密码为单个小写字母
(2) 每位密码的左右两边均有且只有三个大写字母
答案:
str1 = '''ABSaDKSbRIHcRHGcdDIF'''
countA = 0 # 统计前边的大写字母
countB = 0 # 统计小写字母
countC = 0 # 统计后边的大写字母
length = len(str1)
for i in range(length):
if str1[i] == '\n':
continue
if str1[i].isupper():
if countB:
countC += 1
else:
countC = 0
countA += 1
if str1[i].islower():
if countA != 3:
countA = 0
countB = 0
countC = 0
else:
if countB:
countA = 0
countB = 0
countC = 0
else:
countB = 1
countC = 0
target = i
if countA == 3 and countC == 3:
if i+1 != length and str1[i+1].isupper():
countB = 0
countC = 0
else:
print(str1[target], end=' ')
countA = 3
countB = 0
countC = 0
问题:
str1 = '''ABSaDKSbRIHcRHGcdDIF''' 这个字符串中隐藏的密码应该是a b c,如果我没理解错的话,但是小甲鱼给出的代码只打印出了b c,请问是什么问题呢?是答案不对还是我某个环节出问题了? |
|