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
全部评论

相关推荐

10-09 00:50
已编辑
长江大学 算法工程师
不期而遇的夏天:1.同学你面试评价不错,概率很大,请耐心等待;2.你的排名比较靠前,不要担心,耐心等待;3.问题不大,正在审批,不要着急签其他公司,等等我们!4.预计9月中下旬,安心过节;5.下周会有结果,请耐心等待下;6.可能国庆节前后,一有结果我马上通知你;7.预计10月中旬,再坚持一下;8.正在走流程,就这两天了;9.同学,结果我也不知道,你如果查到了也告诉我一声;10.同学你出线不明朗,建议签其他公司保底!11.同学你找了哪些公司,我也在找工作。
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务