鱼C论坛

 找回密码
 立即注册

咖啡的旅游记

https://fishc.com.cn/?521662

第20讲函数:内嵌函数和闭包。我写的简直就是笑话,扯淡。哈哈哈

已有 413 次阅读2018-3-20 21:55 |个人分类:课后练习-自嘲

====================================
'每位密码为单个小写字母'
'每位密码的左右两边均有且只有三个大写字母'
'list(enumerate(str))'
'zip'
def finpass(spass):
  i=0
  for each in spass:
    if i>=4 and i<=len(spass)-3 and each.islower() :
      if spass[i+1].isupper() and spass[i+2].isupper() and spass[i+3].isupper() and\
      spass[i+4].isupper()!=True and spass[i-1].isupper() and spass[i-2].isupper() and\
      spass[i-3].isupper() and spass[i-4].isupper()!=True:
        print(each,end='')
    i+=1
===================================小甲鱼写的太高深,脑子回路,转不过来===================================
str1 = ''''''

countA = 0  # 统计前边的大写字母
countB = 0  # 统计小写字母
countC = 0  # 统计后边的大写字母
length = len(str1)

for i in range(length):
    if str1[i] == '\n':
        continue

    """
    |如果str1[i]是大写字母:
    |-- 如果已经出现小写字母:
    |-- -- 统计后边的大写字母
    |-- 如果未出现小写字母:
    |-- -- 清空后边大写字母的统计
    |-- -- 统计前边的大写字母
    """
    if str1[i].isupper():
        if countB:
            countC += 1
        else:
            countC = 0
            countA += 1

    """
    |如果str1[i]是小写字母:
    |-- 如果小写字母前边不是三个大写字母(不符合条件):
    |-- -- 清空所有记录,重新统计
    |-- 如果小写字母前边是三个大写字母(符合条件):
    |-- -- 如果已经存在小写字母:
    |-- -- -- 清空所有记录,重新统计(出现两个小写字母)
    |-- -- 如果该小写字母是唯一的:
    |-- -- -- countB记录出现小写字母,准备开始统计countC
    """
    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

    """
    |如果前边和后边都是三个大写字母:
    |-- 如果后边第四个字母也是大写字母(不符合条件):
    |-- -- 清空记录B和C,重新统计
    |-- 如果后边仅有三个大写字母(符合所有条件):
    |-- -- 打印结果,并清空所有记录,进入下一轮统计
    """
    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
==================================================


路过

雷人

握手

鲜花

鸡蛋

发表评论 评论 (1 个评论)

回复 咖啡的旅游记 2018-3-20 22:08
死心眼,直肠子,倔驴

facelist

您需要登录后才可以评论 登录 | 立即注册

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-12 23:36

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

返回顶部