python解法,参考里面的写法分别计算,字母,数字和符号的个数,分类讨论,注意讨论细节中间错了很多次

密码强度等级

http://www.nowcoder.com/questionTerminal/52d382c2a7164767bca2064c1c9d5361

encoding:utf-8

if name == 'main':
log = 0
while True:
try:
s = raw_input()
if len(s)<=4:
score = 5
elif len(s)<=7 and len(s)>=5:
score = 10
elif len(s)>= 8:
score = 25
else:
score = 0
num_alpha_up = 0
num_alpha_low = 0
num_digit = 0
num_sym = 0
for i in s:
if i.isdigit():
num_digit=num_digit+1
elif i.islower():
num_alpha_low +=1
elif i.isupper():
num_alpha_up+=1
else:
num_sym+=1
#纯数字
if num_digit == len(s):
if len(s) ==1:
score = score +10
else:
score = score+20
#纯字母
if num_alpha_up +num_alpha_low == len(s):
if num_alpha_low == len(s) or num_alpha_up == len(s):
score = score+10
else:
score =score+20
if log == 1:
print '纯字母,score = ',score
# 纯符号
if num_sym == len(s):
if len(s) == 1:
score = score + 10
else:
score = score + 25
#字母+数字
if num_digit>0 and num_alpha_low+num_alpha_up > 0 and num_sym == 0:
if num_digit+num_alpha_up+num_alpha_low ==len(s):
score = score+2
if num_digit == 1:
score+=10
elif num_digit >1:
score +=20
if num_alpha_up == 0 or num_alpha_low == 0:
score+=10
elif num_alpha_low>0 and num_alpha_up>0:
score+=20
#字母+符号
if num_sym > 0 and num_alpha_up+num_alpha_low > 0 and num_digit == 0:
if num_sym == 1:
score = score+10
elif num_sym >1:
score = score+25
if num_alpha_low == 0 or num_alpha_up == 0:
score = score+10
else:
score = score+20
#数字+符号
if num_digit >0 and num_sym > 0 and num_alpha_up+num_alpha_low == 0:
if num_digit == 1:
score = score +10
elif num_digit >1:
score = score +20
if num_sym == 1:
score = score +10
elif num_sym >1:
score = score+25
#字母+数字+符号
if num_digit>0 and num_alpha_up +num_alpha_low>0 and num_sym>0:
#字母+数字+符号
if num_alpha_low == 0 or num_alpha_up ==0:
score = score+3+10
if log == 1:
print '大字母+数字+符号,score = ', score
# 大小写字母+数字+符号
else:
score = score+5+20
#一个数字
if num_digit == 1:
score += 10
elif num_digit > 1:
score += 20
#一个符号
if num_sym == 1:
score+=10
elif num_sym:
score+=25

            if log == 1:
                print '字母+数字+符号,score = ',score

        # print 'score',score


        if score>= 90:
            print 'VERY_SECURE'
        elif score>=80:
            print 'SECURE'
        elif score>=70:
            print 'VERY_STRONG'
        elif score>=60:
            print 'STRONG'
        elif score>=50:
            print 'AVERAGE'
        elif score>=25:
            print 'WEAK'
        elif score>=0:
            print 'VERY_WEAK'
        else:
            print 'error'
    except:
        break
全部评论

相关推荐

个人背景:学院二本计科专业&nbsp;大二开始实习个人经历:安克创新&nbsp;、理想汽车、字节跳动碎碎念:我做事只有三分钟热度。看到进了大厂的同学,我会羡慕,也会跟着努力上进;但遇到好看的小说,我又会放下手头的事沉迷其中,之前的坚持也就中断了。我有些自卑,总觉得自己学历和外貌都不够好。之前偶然在网上受到关注,我就喜欢上了上网,因为这里有很多人认可我。但我也很在意别人的评价,偶尔看到嘲讽的言论,会触发我的自卑情绪,让我感到愤怒。有时候我会强硬地回怼,有时候又会懦弱地选择无视。我也有虚荣心。不管是拿到安克、理想还是字节的机会,我在分享的时候都会带着这份心思。我会特意强调自己学历不好,是为了衬托出过程的艰难,以此显得自己更厉害。我知道,人往往会炫耀自己缺少的东西,来掩盖内心的空洞。我总想着走捷径,不太喜欢踏踏实实地做事。找实习的时候,我花了更多时间在研究面试技巧上,而不是提升专业能力。我会反复听面试录音分析技巧,看面试教程学习怎么和不同的面试官沟通,还会每天自言自语练习语言表达,同学都觉得我有点奇怪。我的实习生涯里,侥幸和运气占了很大一部分。我总在想,如果有一天我失去了这份幸运,这些特质可能会让我一蹶不振。ps:&nbsp;很多人会问我学习路线和经验&nbsp;但是就像我上面说的&nbsp;我的实习过程靠的很多是关键节点的运气&nbsp;技术上面我可能不如很多人&nbsp;&nbsp;所以请大家理性求助和理性参考我的回答&nbsp;附上我的投递记录
我的offer在哪里...:从去年看到现在,飞升哥就是榜样
我的求职进度条
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务