|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 anne0506 于 2015-11-2 13:09 编辑
1. 请用已学过的知识编写程序,找出小甲鱼藏在下边这个长字符串中的密码,密码的埋藏点符合以下规律:
每位密码为单个小写字母
每位密码的左右两边均有且只有三个大写字母
- str1 = '''拷贝过来的字符串'''
- 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 == 1:
- countC += 1
- countA = 0
- else:
- countA += 1
- continue
- if str1[i].islower() and countA == 3:
- countB = 1
- countA = 0
- target = i
- continue
- if str1[i].islower() and countC == 3:
- print(str1[target], end='')
- countA = 0
- countB = 0
- countC = 0
复制代码
这是小甲鱼的代码,由于拷贝的文件下载不下来,我就自己编了个字符串'ABCbDEF'
按理说应该会返回密码'b'
但是却是什么都没有返回出来,不知道是什么问题,就大神指点
然后这是我自己编写的,也得不出密码 ,求指点
- str1 = 'ABCbDEF'
- length = len(str1)
- for i in range(length):
- if str1[i].islower():
- if str1[i-3:i].isupper() and str1[i+1:i+4].isupper():
- if str1[i-4] == '\n' and str1[i+4] == '\n':
- print('密码:',i)
-
复制代码
|
评分
-
查看全部评分
|