首页 > 试题广场 >

密码强度等级

[编程题]密码强度等级
  • 热度指数:143925 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
密码按如下规则进行计分,并根据不同的得分为密码进行安全等级划分。

一、密码长度:
5 分: 小于等于4 个字符
10 分: 5 到7 字符
25 分: 大于等于8 个字符

二、字母:
0 分: 没有字母
10 分: 密码里的字母全都是小(大)写字母
20 分: 密码里的字母符合”大小写混合“

三、数字:
0 分: 没有数字
10 分: 1 个数字
20 分: 大于1 个数字

四、符号:
0 分: 没有符号
10 分: 1 个符号
25 分: 大于1 个符号

五、奖励(只能选符合最多的那一种奖励):
2 分: 字母和数字
3 分: 字母、数字和符号
5 分: 大小写字母、数字和符号

最后的评分标准:
>= 90: 非常安全
>= 80: 安全(Secure)
>= 70: 非常强
>= 60: 强(Strong)
>= 50: 一般(Average)
>= 25: 弱(Weak)
>= 0:  非常弱(Very_Weak)

对应输出为:

VERY_SECURE
SECURE
VERY_STRONG
STRONG
AVERAGE
WEAK
VERY_WEAK

请根据输入的密码字符串,进行安全评定。

注:
字母:a-z, A-Z
数字:0-9
符号包含如下: (ASCII码表可以在UltraEdit的菜单view->ASCII Table查看)
!"#$%&'()*+,-./     (ASCII码:0x21~0x2F)
:;<=>?@             (ASCII码:0x3A~0x40)
[\]^_`              (ASCII码:0x5B~0x60)
{|}~                (ASCII码:0x7B~0x7E)

提示:
1 <= 字符串的长度<= 300

输入描述:

输入一个string的密码



输出描述:

输出密码等级

示例1

输入

38$@NoNoN

输出

VERY_SECURE

说明

样例的密码长度大于等于8个字符,得25分;大小写字母都有所以得20分;有两个数字,所以得20分;包含大于1符号,所以得25分;由于该密码包含大小写字母、数字和符号,所以奖励部分得5分,经统计得该密码的密码强度为25+20+20+25+5=95分。
         
示例2

输入

Jl)M:+

输出

AVERAGE

说明

示例2的密码强度为10+20+0+25+0=55分。        
from functools import reduce
while True:
    try:
        s = input()
        password = []
        password.extend(s)
        p1,p2,p3,p4 = [],[],[],[]

        for i in password:
            if i.isupper():
                p1.append(i)
            elif i.islower():
                p2.append(i)
            elif i.isdigit():
                p3.append(i)
            else:
                p4.append(i)

        score = []
        if len(s) <= 4:         
            score.append(5)
        elif 5 <= len(s) <= 7:
            score.append(10)
        else:
            score.append(25)

        if p1 or p2:        
            if len(p1) == 0 or len(p2) == 0:
                score.append(10)
            else:
                score.append(20)

        if len(p3) == 1:        
            score.append(10)
        elif len(p3) > 1:
            score.append(20)

        if len(p4) == 1:       
            score.append(10)
        elif len(p4) > 1:
            score.append(25)

        if (p1 or p2) and  p3:      
            score.append(2)
        elif (p1 or p2) and p3 and p4:
            score.append(3)
        elif p1 and p2 and p3 and p4:
            score.append(5)

        result = reduce(lambda x,y : x+y,score)
        if result >= 90:
            print('VERY_SECURE')
        elif result >= 80:
            print('SECURE')
        elif result >= 70:
            print('VERY_STRONG')
        elif result >= 60:
            print('STRONG')
        elif result >= 50:
            print('AVERAGE')
        elif result >= 25:
            print('WEAK')
        elif result >= 0:
            print('VERY_WEAK')
    except:break

编辑于 2020-03-30 10:45:58 回复(9)
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int get(string str)
{
    int sum=0,a1=0,a2=0,a3=0,a4=0,a5=0;
    vector<char>a21,a22,a31,a41;
    
    int len=str.size();
    if(len<=4)a1=5;
    else if(len>=8)a1=25;
    else a1=10;
        
    for(int i=0;i<len;++i)
        if(str[i]<='z'&&str[i]>='a')a21.push_back(str[i]);
        else if(str[i]<='Z'&&str[i]>='A')a22.push_back(str[i]);
        else if(str[i]<='9'&&str[i]>='0')a31.push_back(str[i]);
        else a41.push_back(str[i]);
    int lena21=a21.size(),lena22=a22.size(),lena31=a31.size(),lena41=a41.size();
    
    if(lena21==0&&lena22==0)a2=0;
    else if(lena21!=0&&lena22!=0)a2=20;
    else a2=10;
        
    if(lena31==0)a3=0;
    else if(lena31==1)a3=10;
    else a3=20;
        
    if(lena41==0)a4=0;
    else if(lena41==1)a4=10;
    else a4=25;

    if(lena21&&lena22&&lena31&&lena41)a5=5;
    else if((lena21||lena22)&&lena31&&lena41)a5=3;
    else if((lena21||lena22)&&lena31)a5=2;
    else a5=0;
        
    sum=a1+a2+a3+a4+a5;
    return sum;
}
int main()
{
   string str;
   while(cin>>str)
   {
       int sum=get(str);
       switch(sum/10)
       {
           case 9:cout<<"VERY_SECURE"<<endl;break;
           case 8:cout<<"SECURE"<<endl;break;
           case 7:cout<<"VERY_STRONG"<<endl;break;
           case 6:cout<<"STRONG"<<endl;break;
           case 5:cout<<"AVERAGE"<<endl;break;
           default:
           {
               if(sum>=25)cout<<"WEAK"<<endl;
               else cout<<"VERY_WEAK"<<endl;
           }
       }
   }
    return 0;
}

发表于 2016-08-12 11:33:21 回复(1)
import java.util.*;
import java.io.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String input = scanner.nextLine();
            GetPwdSecurityLevel(input);
        }
    }
    
    public static void GetPwdSecurityLevel(String input) {
        char[] inputArray = input.toCharArray();
        int score = 0;
        int letterNum = 0;
        int lowercaseNum = 0;
        int uppercaseNum = 0;
        int digitNum = 0;
        int charNum = 0;
        // count all type char nums
        for (char c : inputArray) {
            // if is lowercase letter
            if (Character.isLowerCase(c)) {
                lowercaseNum++;
                letterNum++;
            }
            // if is uppercase letter
            else if (Character.isUpperCase(c)) {
                uppercaseNum++;
                letterNum++;
            }
            // if is digits
            else if (Character.isDigit(c)) {
                digitNum++;
            }
            // if is character
            else {
                charNum++;
            }
        }
        // password length
        // length <= 4
        int passLength = inputArray.length;
        if (passLength <= 4) {
            score += 5;
        }
        // 5 <= length <= 7
        else if (passLength >= 5 && passLength <= 7) {
            score += 10;
        }
        // length >= 8;
        else {
            score += 25;
        }
        // letter
        // no letters
        if (letterNum < 1) {
            score += 0;
        }
        else if (letterNum > 0) {
            // only lowercase or only uppercase
            if (lowercaseNum < 1 || uppercaseNum < 1) {
                score += 10;
            }
            // contain both lowercase and uppercase
            else {
                score += 20;
            }
        }
        // digits
        // no digits
        if (digitNum < 1) {
            score += 0;
        }
        // only one digit
        else if (digitNum == 1) {
            score += 10;
        } 
        // more than one digits
        else {
            score += 20;
        }
        // character
        // no character
        if (charNum < 0) {
            score += 0;
        }
        // only one character
        else if (charNum == 1) {
            score += 10;
        }
        // char.num > 1
        else {
            score += 25;
        }
        // award
        // contain both letter and digit
        if (letterNum > 0 && digitNum > 0) {
            score += 2;
        }
        // contain both letter, digit, and character
        if (letterNum > 0 && digitNum > 0 && charNum > 0) {
            score += 3;
        }
        // contain both lowercase, uppercase, digit, and character
        if (lowercaseNum > 0 && uppercaseNum > 0 && digitNum > 0 && charNum > 0) {
            score += 5;
        }
        
        String secLevel = new String();
        // judge security level
        if (score >= 90) {
            secLevel = "VERY_SECURE";
        }
        else if (score >= 80) {
            secLevel = "SECURE";
        }
        else if (score >= 70) {
            secLevel = "VERY_STRONG";
        }
        else if (score >= 60) {
            secLevel = "STRONG";
        }
        else if (score >= 50) {
            secLevel = "AVERAGE";
        }
        else if (score >= 25) {
            secLevel = "WEAK";
        }
        else if (score >= 0) {
            secLevel = "VERY_WEAK";
        }
        System.out.println(secLevel);
    }
}

发表于 2019-08-23 09:51:12 回复(1)
// 1.将输入的字符串转换成字符数组,可以顺便取得密码长度
// 2.定义一个整型变量score用于记录最终的得分
// 3.定义三个整型变量letterNum、upperCaseNum、lowerCaseNum,分别记录所有字母数量、大写字母数量、小写字母数量
// 4.定义一个整型变量digitNum,用于记录数字字符的数量
// 5.定义一个charNum,用于记录符号的数量
// 6.遍历字符数组,统计每种字符的数量,然后确定总分
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            String s = in.nextLine();//考虑密码中可能有空格,所以要接收空格
            char[] cs = s.toCharArray();
            int score = 0;// 最终的得分
            int letterNum = 0;// 所有字母的数量
            int upperCaseNum = 0;// 大写字母的数量
            int lowerCaseNum = 0;// 小写字母的数量
            int digitNum = 0;// 数字字符的数量
            int charNum = 0;// 符号的数量
            // 遍历字符数组,统计每种字符的数量
            for(char c : cs){
                if(Character.isLowerCase(c)){
                    lowerCaseNum++;
                    letterNum++;
                }else if(Character.isUpperCase(c)){
                    upperCaseNum++;
                    letterNum++;
                }else if(Character.isDigit(c)){
                    digitNum++;
                }else{
                    charNum++;
                }
            }
            // 根据密码长度来确定得分
            if(cs.length <= 4){
                score += 5;
            }else if(cs.length <= 7){
                score += 10;
            }else if(cs.length >= 8){
                score += 25;
            }
            // 根据字母情况来确定得分
            if(letterNum < 1){
                score += 0;
            }else if(letterNum == upperCaseNum || letterNum == lowerCaseNum){
                score += 10;
            }else if(upperCaseNum > 0 && lowerCaseNum > 0){
                score += 20;
            }
            // 根据数字的情况来确定得分
            if(digitNum < 1){
                score += 0;
            }else if(digitNum == 1){
                score += 10;
            }else if(digitNum > 1){
                score += 20;
            }
            // 根据符号的情况来确定得分
            if(charNum < 1){
                score += 0;
            }else if(charNum == 1){
                score += 10;
            }else if(charNum > 1){
                score += 25;
            }
            // 根据奖励的情况来确定得分,注意这个逻辑是三选一,所以要倒着来
            if(upperCaseNum > 0 && lowerCaseNum > 0 && digitNum > 0 && charNum > 0){
                score += 5;
            }else if((upperCaseNum > 0 && digitNum > 0 && charNum > 0) || (lowerCaseNum > 0 && digitNum > 0 && charNum > 0)){
                score += 3;
            }else if((upperCaseNum > 0 && digitNum > 0) || (lowerCaseNum > 0 && digitNum > 0)){
                score += 2;
            }
            // 输出结果
            if(score >= 90){
                System.out.println("VERY_SECURE");
            }else if(score >= 80){
                System.out.println("SECURE");
            }else if(score >= 70){
                System.out.println("VERY_STRONG");
            }else if(score >= 60){
                System.out.println("STRONG");
            }else if(score >= 50){
                System.out.println("AVERAGE");
            }else if(score >= 25){
                System.out.println("WEAK");
            }else if(score >= 0){
                System.out.println("VERY_WEAK");
            }
        }
        in.close();
    }
}

编辑于 2020-08-18 00:20:00 回复(1)
def longenth_score(pwd):
    if len(pwd)<=4:
        return 5
    elif len(pwd)>=8:
        return 25
    else:
        return 10
    
def char_score(pwd):
    pn =0
    for p in pwd:
        if p.isalpha():
            pn+=1
    if pn==0:
        return 0
    elif pwd.upper()==pwd&nbs***bsp;pwd.lower()==pwd:
        return 10
    else:
        return 20

def num_score(pwd):
    nn = 0
    for n in pwd:
        if n.isdigit():
            nn +=1
    if nn ==0:
        return 0
    elif nn ==1:
        return 10
    else:
        return 20
def sym_score(pwd):
    for i in pwd:
        if i.isdigit()&nbs***bsp;i.isalpha():
            pwd = pwd.replace(i,'0')
    sn = len(pwd) - pwd.count('0')
    if sn == 0:
        return 0
    elif sn ==1 :
        return 10
    else:
        return 25
    
def reward_score(c_score,n_score,s_score):
    if c_score == 20 and n_score>0 and s_score>0:
        return 5
    elif c_score == 10 and n_score>0 and s_score>0:
        return 3
    elif c_score > 10 and n_score>0 and s_score==0:
        return 2
    else:
        return 0
def pwd_level(total_score):
    if total_score>=90:
        return 'VERY_WEAK'
    elif total_score >=80:
        return 'WEAK'
    elif total_score >=70:
        return 'VERY_STRONG'
    elif total_score >=60:
        return 'STRONG'
    elif total_score >=50:
        return 'AVERAGE'
    elif total_score >=25:
        return 'SECURE'
    else:
        return 'VERY_SECURE'
if __name__ == '__main__':
    while True:
        try:
            pwd = input()
            l_score = longenth_score(pwd)
            c_score = char_score(pwd)
            n_score = num_score(pwd)
            s_score = sym_score(pwd)
            r_score = reward_score(c_score,n_score,s_score)
            total_score = l_score+c_score+n_score+s_score+r_score
            print(pwd_level(total_score))
        except:
            break
笨方法,还算清晰,示例是错的差点坑死我
发表于 2019-12-21 19:46:19 回复(0)
第二个条件题目没说清, 应该这样写:
0分: 没有字母
10分:对于输入字符串出现的字母,全都是小(大)写字母
20分:存在大小写混合字母
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String s = sc.nextLine();
            int[] arr = new int[5];
            // 1.长度
            if (s.length() <= 4) {
                arr[0] = 5;
            } else if(5<=s.length() && s.length()<=7) {
                arr[0] = 10;
            } else{
                arr[0] = 25;
            }
            // 2.字母
            int lowerCount = 0;
            int upperCount = 0;
            int digitCount = 0;
            int symbolCount = 0;
            for(int i=0; i<s.length();i++) {
                if (Character.isUpperCase(s.charAt(i))) {
                    upperCount++;
                } else if (Character.isLowerCase(s.charAt(i))) {
                    lowerCount++;
                }else if (Character.isDigit(s.charAt(i))) {
                    digitCount++;
                } else{   // 这里包括了字符串中可能存在的空格
                    symbolCount++;
                }
            }
            if(lowerCount == 0 && upperCount == 0) {
                arr[1] = 0;
            } else if (lowerCount !=0 && upperCount != 0) {
                arr[1] = 20;
            } else if (lowerCount != 0 || upperCount != 0) {
                arr[1] = 10;
            }
            // 3.数字
            if (digitCount == 0) {
                arr[2] = 0;
            } else if (digitCount == 1) {
                arr[2] = 10;
            } else if (digitCount > 1) {
                arr[2] = 20;
            }
            // 4.符号
            if (symbolCount == 0) {
                arr[3] = 0;
            } else if (symbolCount == 1) {
                arr[3] = 10;
            } else if (symbolCount > 1) {
                arr[3] = 25;
            }
            // 5.奖励
            if ((lowerCount+upperCount) > 0 && digitCount > 0 && symbolCount == 0) {
                arr[4] = 2;
            }else if (lowerCount>0 && upperCount > 0 && digitCount > 0 && symbolCount > 0) {
                arr[4] = 5;
            } else if ((lowerCount+upperCount) > 0 && digitCount > 0 && symbolCount > 0) {
                arr[4] = 3;
            }
            int totalCount = arr[0] + arr[1] + arr[2] + arr[3] + arr[4];
            if (totalCount >= 90) System.out.println("VERY_SECURE");
            if (totalCount >= 80 && totalCount < 90) System.out.println("SECURE");
            if (totalCount >= 70 && totalCount < 80) System.out.println("VERY_STRONG");
            if (totalCount >= 60 && totalCount < 70) System.out.println("STRONG");
            if (totalCount >= 50 && totalCount < 60) System.out.println("AVERAGE");

            if (totalCount >= 25 && totalCount < 50) System.out.println("WEAK");
            if (totalCount >= 0 && totalCount < 25) System.out.println("VERY_WEAK");
        }
    }
}


发表于 2021-03-25 17:02:56 回复(0)
#include <bits/stdc++.h>
using namespace std;
int  length(string s)
{
    int res;
    int n=s.size();
    if(n<=4) res=5;
    else if(n<=7) res=10;
    else res=25;
    return res;
}
int alp(string s)
{
    int res,res1=0,res2=0;
    int n=s.size();
    for(int i=0;i<n;i++)
    {
        if(s[i]>='a' && s[i]<='z') res1++;
        else if(s[i]>='A' && s[i]<='Z') res2++;
    }
        if(res1==0 && res2==0) res=0;
        else if(res1==0 || res2==0) res=10;
        else res=20;
    return res;
}
int dig(string s)
{
    int res,res1=0;
    int n=s.size();
    for(int i=0;i<n;i++)
    {
        if(s[i]>='0' && s[i]<='9') res1++;
    }
        if(res1==0) res=0;
        else if(res1==1) res=10;
        else res=20;
    return res;
}
int sym(string s)
{
    int res,res1=0;
    int n=s.size();
    for(int i=0;i<n;i++)
    {
        if((s[i]>=33 && s[i]<=47)  || (s[i]>=58 && s[i]<=64) || (s[i]>=91 && s[i]<=96) || (s[i]>=123 && s[i]<=126) )
            res1++;
    }
    if(res1==0) res=0;
    else if(res1==1) res=10;
    else res=25;
    return res;
}

int main()
{
    string s;
    while(getline(cin,s))
    {
        int res = length(s)+alp(s)+dig(s)+sym(s);
        if((alp(s)>10) &&  dig(s) &&  sym(s)) res+=5;
        else if(alp(s) && dig(s) &&  sym(s)) res += 3;
        else if(dig(s) && alp(s) ) res+=2;
        if(res>=90) cout<<"VERY_SECURE"<<endl;
        else if(res>=80) cout<<"SECURE"<<endl;
        else if(res>=70) cout<<"VERY_STRONG"<<endl;
        else if(res>=60) cout<<"STRONG"<<endl;
        else if(res>=50) cout<<"AVERAGE"<<endl;
        else if(res>=25) cout<<"WEAK"<<endl;
        else cout<<"VERY_WEAK"<<endl;
    }
        system("pause");
        return 0;
    
} 

发表于 2018-08-06 23:16:48 回复(0)
import java.util.Scanner;

public class Main {
	public static String GetPwdSecurityLevel(String Password) {
		int score = 0;
		
		int length = Password.length();
		
		if (length <= 4)
			score += 5;
		else if (length <= 7)
			score += 10;
		else
			score += 25;
		
		char[] c = Password.toCharArray();
		int[] type = new int[4];
		int countNum = 0;
		int countSign = 0;
		
		for (int i = 0; i < length; ++i) {
			
			if (c[i] >= 'a' && c[i] <= 'z')
				type[0] = 1;
			else if (c[i] <= 'Z' && c[i] >= 'A')
				type[1] = 1;
			else if ((c[i] >= '0' && c[i] <= '9')) {
				type[2] = 1;
				++countNum;
			} else {
				type[3] = 1;
				++countSign;
			}
		}
		
		if ((type[0] & type[1]) == 1) {
			score += 20;
			if ((type[3] & type[2]) == 1)
				score += 5;
			else if (type[2] == 1)
				score += 2;
		} else if ((type[0] | type[1]) == 1) {
			score += 10;
			if ((type[3] & type[2]) == 1)
				score += 3;
			else if (type[2] == 1)
				score += 2;
		}
		
		if (countNum == 1) {
			score += 10;
		} else if (countNum > 1) {
			score += 25;
		}
		
		if (countSign == 1) {
			score +=10;
		} else if (countSign > 1) {
			score += 25;
		}
		
		
		if (score >= 90)
			return "VERY_SECURE";
		else if (score >= 80)
			return "SECURE";
		else if (score >= 70)
			return "VERY_STRONG";
		else if (score >= 60)
			return "STRONG";
		else if (score >= 50)
			return "AVERAGE";
		else if (score >= 25)
			return "WEAK";
		else if (score >= 0)
			return "VERY_WEAK";
		return "Wrong";
	}
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String pass = "";
		while (scanner.hasNext()) {
			pass = scanner.nextLine();
			System.out.println(GetPwdSecurityLevel(pass));
		}
	}
}


编辑于 2017-03-21 16:12:32 回复(1)
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String line = sc.nextLine();
            int score = 0;
            if(line.length()>=8) {
                score += 25;
            } else if(line.length()>=5) {
                score += 10;
            } else if(line.length()<=4) {
                score += 5;
            }
            int upplet = 0;
            int dowlet = 0;
            int numlet = 0;
            int othlet = 0;
            for(int i=0; i< line.length(); i++) {
                if(line.charAt(i)>='A' && line.charAt(i)<='Z') {
                    upplet ++;
                } else if(line.charAt(i)>='a' && line.charAt(i)<='z') {
                    dowlet ++;
                } else if(line.charAt(i)>='0' && line.charAt(i)<='9') {
                    numlet ++;
                } else {
                    othlet ++;
                }
            }
            if((upplet!=0 && dowlet==0) || (upplet==0 && dowlet!=0)) {
                score += 10;
            } else if(upplet!=0 && dowlet!=0) {
                score += 20;
            }
            if(numlet == 1) {
                score += 10;
            } else if(numlet > 1) {
                score += 20;
            }
            if(othlet == 1) {
                score += 10;
            } else if(othlet > 1) {
                score += 25;
            }
            if(numlet!=0 && upplet!=0 && dowlet!=0 && othlet!=0) {
                score += 5;
            } else if(numlet!=0 && (upplet!=0 || dowlet!=0) && othlet!=0) {
                score += 3;
            } else if(numlet!=0 && (upplet!=0 || dowlet!=0)) {
                score += 2;
            }
            if(score>=90)
                System.out.println("VERY_SECURE");
            else if(score>=80)
                System.out.println("SECURE");
            else if(score>=70)
                System.out.println("VERY_STRONG");
            else if(score>=60)
                System.out.println("STRONG");
            else if(score>=50)
                System.out.println("AVERAGE");
            else if(score>=25)
                System.out.println("WEAK");
            else if(score>=0)
                System.out.println("VERY_WEAK");
        }
    }
}

发表于 2018-10-09 12:56:58 回复(0)
#include<bits/stdc++.h>  //太难了这题,起码耗了我一个半小时,中间需要修正的细节太多了
using namespace std;
int getLong(string s);
int getAlp(string s);
int getNum_punct(string s);
int getReward();
int low =0,upper = 0,cot =0,punct=0;

int main(){
    string s;
    while(getline(cin,s)){
        low =0,upper = 0,cot =0,punct=0;
        string ans;
        int score =0;
        score += getLong(s);
        score += getAlp(s);
        score += getNum_punct(s);
        score += getReward();
        if(score>=90) ans = "VERY_SECURE";
        else if(score>=80) ans = "SECURE";
        else if(score>=70) ans = "VERY_STRONG";
        else if(score>=60) ans = "STRONG";
        else if(score>=50) ans = "AVERAGE";
        else if(score>=25) ans = "WEAK";
        else ans = "VERY_WEAK";
        cout<<ans<<endl;
    }
}

int getLong(string s){
    int n=s.length();
    if(n<=4) return 5;
    else if(n>=8) return 25;
    return 10;
}
int getAlp(string s){
    int al=1;
    for(char i:s){
        if(isupper(i)) upper = 1;
        else if(islower(i)) low = 1;
        if(!isalpha(i)) al = 0;    // not all are alpha
    }
    if(upper && low) return 20;
    else if(upper || low) return 10;
//     else if(upper==0 && low==0) return 0;
//     else if(al) return 10;
    if(!(upper || low)) return 0;
    return 0;
}
int getNum_punct(string s){
    int sum =0;
    for(char i:s){
        if(isdigit(i)) cot++;
        if(ispunct(i)) punct++;
    }
    if(cot==1) sum+=10;
    else if(cot>1) sum+=20;
    if(punct==1) sum+= 10;
    else if(punct>1) sum += 25;
    return sum;
}

int getReward(){
    int res = 0;
    if(upper&&cot&&low&&punct) res+=5;
    else if((low&&cot&&punct)|| (upper&&cot&&punct)) res+=3;
    else if((low&&cot) || (upper&&cot)) res+=2; 
    return res;
}
发表于 2022-01-06 14:05:16 回复(0)
var read
while(read = readline()) {
    console.log(getLevel(read))
}

function getLevel(readStr) {
    // 统计输入字符的小写字母,大写字母,数字,特殊字符的个数
    var obj = {
        "daxiaoZimu":0,
        "xiaoxieZimu":0,
        "shuZi":0,
        "teShuzifu":0
    }
    var readStrArr = readStr.split('')
    for(let item of readStrArr) {
       if(item >= 'a' && item <= 'z' ){
            obj.xiaoxieZimu += 1;
            continue;
        }
        
        if(item >= 'A' && item <= 'Z'){
            obj.daxiaoZimu += 1;
            continue;
        }
        
        if(item >= '0' && item <= '9'){
            obj.shuZi += 1;
            continue;
        }
        
        obj.teShuzifu += 1; 
    }
    var score = 0
    // 密码长度
    if(readStr.length <= 4) {
        score += 5
    } else if(readStr.length <= 7 && readStr.length >= 5) {
        score += 10
    } else if(readStr.length >= 8) {
        score += 25
    }
    
    // 全是小写 全是大写
    if((obj.daxiaoZimu > 0 && obj.xiaoxieZimu === 0) || (obj.daxiaoZimu === 0 && obj.xiaoxieZimu > 0)) {
         score += 10
    }
//     if((obj.daxiaoZimu > 0 && obj.xiaoxieZimu === 0 && obj.shuZi === 0 && obj.teShuzifu === 0)
//        || (obj.xiaoxieZimu > 0 && obj.daxiaoZimu === 0 && obj.shuZi === 0 && obj.teShuzifu === 0)) {
//          score += 10
//     }
    // 大小写字母混合
    if(obj.daxiaoZimu > 0 && obj.xiaoxieZimu > 0) {
         score += 20
    }
     // 一个数字
    if(obj.shuZi === 1) {
        score += 10
    }
    // 大于1个数字
    if(obj.shuZi > 1) {
        score += 20
    }
    // 1个符号
    if(obj.teShuzifu === 1) {
        score += 10
    }
    // 大于1个符号
     if(obj.teShuzifu > 1) {
        score += 25
    }
    // 字母和数字
    if((obj.daxiaoZimu > 0 && obj.shuZi > 0 && obj.xiaoxieZimu === 0 && obj.teShuzifu === 0)
      || (obj.xiaoxieZimu > 0 && obj.shuZi > 0 && obj.daxiaoZimu === 0 && obj.teShuzifu === 0)){
        score += 2
    }
    
    // 字母数字和符号
     if((obj.daxiaoZimu > 0 && obj.shuZi > 0 && obj.xiaoxieZimu === 0 && obj.teShuzifu > 0)
      || (obj.xiaoxieZimu > 0 && obj.shuZi > 0 && obj.daxiaoZimu === 0 && obj.teShuzifu > 0)){
        score += 3
     }
    
    // 大小写字母数字和符号
     if(obj.daxiaoZimu > 0 && obj.shuZi > 0 && obj.xiaoxieZimu > 0 && obj.teShuzifu > 0){
        score += 5
     }
    var tip = ''
    if(score >= 95){
        tip = 'VERY_SECURE'
    } else if(score >= 80 && score < 95) {
        tip = 'SECURE'
    } else if(score >= 70 && score < 80) {
        tip = 'VERY_STRONG'
    } else if(score >= 60 && score < 70) {
        tip = 'STRONG'
    } else if(score >= 50 && score < 60) {
        tip = 'AVERAGE'
    } else if(score >= 25 && score < 50) {
        tip = 'WEAK'
    } else {
        tip = 'VERY_WEAK'
    }
//     console.log(score)
    return tip
}
// 25+20+25+3
发表于 2021-10-03 23:41:52 回复(0)
import java.util.*;
import java.io.*;

public class Main {
        
    public static void main(String[] args) throws Exception{
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String str = "";
        while ((str = bufferedReader.readLine()) != null) {
            int number = 0;
            int len = str.length();
            int character1 = 0, character2 = 0;
            int numberal = 0;
            int symbol = 0;
            int reward = 0;
            char[] chars = str.toCharArray();
            while (number < len) {
                if ((chars[number] >= 'a' && chars[number] <= 'z')) {
                    character1++;
                } else if(chars[number] >= 'A' && chars[number] <= 'Z') {
                    character2++;
                } else if (chars[number] >= '0' && chars[number] <= '9') {
                    numberal++;
                } else {
                    symbol++;
                }
                number++;
            }
            int result = 0;
            if (len < 5) {
                result += 5;
            } else if (len < 8) {
                result += 10;
            } else {
                result += 25;
            }
            if ((character1 > 0 && character2 == 0) || (character2 > 0 && character1 == 0)) {
                result += 10;
            } else if (character1 > 0 && character2 > 0) {
                result += 20;
            }
            if (numberal == 1) {
                result += 10;
            } else if (numberal > 1) {
                result += 20;
            }
            if (symbol == 1) {
                result += 10;
            } else if (symbol > 1) {
                result += 25;
            }
            if (character1 > 0 && character2 > 0 && numberal > 0 && symbol > 0) {
                result += 5;
            } else if ((character1 > 0 || character2 > 0) && numberal > 0 && symbol > 0) {
                result += 3;
            } else if ((character1 > 0 || character2 > 0) && numberal > 0) {
                result += 2;
            }
            switch(result / 10) {
                case 0:
                case 1:
                case 2:
                    if (result < 25) {
                        System.out.println("VERY_WEAK");
                    } else {
                        System.out.println("WEAK");
                    }
                    break;
                case 3:
                case 4:
                    System.out.println("WEAK");
                    break;
                case 5:
                    System.out.println("AVERAGE");
                    break;
                case 6:
                    System.out.println("STRONG");
                    break;
                case 7:
                    System.out.println("VERY_STRONG");
                    break;
                case 8:
                    System.out.println("SECURE");
                    break;
                case 9:
                case 10:
                case 11:
                    System.out.println("VERY_SECURE");
                    break;
                default:
                    break;
            }
        }
        
    }
}

发表于 2021-07-29 15:26:05 回复(0)
这种题不难,纯粹恶心人
发表于 2021-07-22 17:00:45 回复(0)
import java.util.*;
/**
 * @author hll[yellowdradra@foxmail.com]
 * @description 密码强度等级
 * @date 2021-05-13 23:34
 **/
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String password = scanner.nextLine();

            int numberCount = 0;
            int lowerLetterCount = 0;
            int upperLetterCount = 0;
            int symbolCount = 0;

            int difficultyGoal = 0;

            int len = password.length();

            for (int i = 0; i < password.length(); i++) {
                char c = password.charAt(i);
                if (c <= '9' && c >= '0') {
                    numberCount++;
                } else if (c <= 'z' && c >= 'a') {
                    lowerLetterCount++;
                } else if (c <= 'Z' && c >= 'A') {
                    upperLetterCount++;
                } else {
                    symbolCount++;
                }
            }

            difficultyGoal += len <= 4 ? 5 : len < 8 ? 10 : 25;
            difficultyGoal += lowerLetterCount > 0 && upperLetterCount > 0 ? 20
                    : lowerLetterCount != upperLetterCount && (lowerLetterCount == 0 || upperLetterCount == 0)? 10 : 0;
            difficultyGoal += numberCount == 0 ? 0 : numberCount == 1 ? 10 : 20;
            difficultyGoal += symbolCount == 0 ? 0 : symbolCount == 1 ? 10 : 25;
            difficultyGoal += lowerLetterCount > 0 && upperLetterCount > 0 && numberCount > 0 && symbolCount > 0 ? 5
                    : lowerLetterCount == 0 || upperLetterCount == 0 ? 3 : symbolCount == 0 ? 2 : 0;

            String[] levels = {"AVERAGE", "STRONG", "VERY_STRONG", "SECURE", "VERY_SECURE"};
            String difficultyLevel = difficultyGoal < 25 ? "VERY_WEAK"
                    : difficultyGoal < 50 ? "WEAK"
                    : levels[(difficultyGoal / 10) - 5];
            System.out.println(difficultyLevel);
        }
    }
}


发表于 2021-05-14 01:08:48 回复(0)

3 分: 字母、数字和符号

5 分: 大小写字母、数字和符号
这两个规则怎么理解?
发表于 2021-01-27 15:15:28 回复(0)
# 思路:将统计情况放主函数中一起写,避免分开写时多次遍历密码字符串。

while True:
    try:
        password = input().strip()
        score = 0  # 初始化得分为0
        # 长度得分
        if len(password) <= 4:
            score += 5
        elif 5 <= len(password) <= 7:
            score += 10
        else:
            score += 25
        # 字母、数字、符号统计(是否出现过、出现的个数)
        alpha, Alpha, digit, digit_num, symbol, symbol_num = 0, 0, 0, 0, 0, 0
        for ch in password:
            if ch.islower():
                alpha = 1
            elif ch.isupper():
                Alpha = 1
            elif ch.isdigit():
                digit = 1
                digit_num += 1
            else:
                symbol = 1
                symbol_num += 1
        # 字母得分
        if (alpha and not Alpha) or (Alpha and not alpha):
            score += 10
        elif alpha and Alpha:
            score += 20
        # 数字得分
        if digit_num == 1:
            score += 10
        elif digit_num > 1:
            score += 20
        # 符号得分
        if symbol_num == 1:
            score += 10
        elif symbol_num > 1:
            score += 25
        # 奖励得分
        # 此写法错误,本该属于第三种加分的情况被第二种加分情况拦截住了,加成了第二种情况的分数。
        # if (alpha or Alpha) and digit and not symbol:
        #     score += 2
        # elif (alpha or Alpha) and digit and symbol:
        #     score += 3
        # elif alpha and Alpha and digit and symbol:
        #     score += 5
        if alpha and Alpha and digit and symbol:
            score += 5
        elif (alpha or Alpha) and digit and symbol:
            score += 3
        elif (alpha or Alpha) and digit:
            score += 2
        # 分数等级
        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')
        else:
            print('VERY_WEAK')
    except:
        break

编辑于 2020-12-28 18:12:18 回复(0)
while(True):
    try:
        s = input()
        secLength = len(s)
        upperCount = 0
        lowerCount = 0
        numCount = 0
        score = 0
        charCount = 0

        for i in s:
            # 数字个数
            if(i.isdigit()):
                numCount+=1
            elif(i.islower()):
                lowerCount+=1
            elif(i.isupper()):
                upperCount+=1
            else:
                charCount+=1

        if (secLength <= 4):
            score += 5
        elif (5 < secLength <= 7):
            score += 10
        elif (secLength >= 8):
            score += 25

        if (numCount == 0):
            score += 0
        elif (numCount==1):
            score += 10
        elif (numCount >= 1):
            score += 20

        if(upperCount==1 and lowerCount==0):
            score+=0
        elif(upperCount==0 and lowerCount>0) or (upperCount>0 and lowerCount==0):
            score+=10
        elif(upperCount>0 and lowerCount>0):
            score+=20
    except:
        break

    if (charCount == 0):
        score += 0
    elif (charCount==1):
        score += 10
    elif (charCount >= 1):
        score += 25

    if(numCount>0 and (upperCount>0 or lowerCount>0) and charCount==0):
        score+=2
    elif (numCount > 0 and (upperCount > 0 or lowerCount > 0) and charCount > 0):
        score += 3
    elif (numCount > 0 and upperCount > 0 and lowerCount > 0 and charCount == 0):
        score += 5

    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')
    else:
        print('VERY_WEAK')
发表于 2020-07-11 12:11:55 回复(0)
import string
import sys


def check_passwd(pwd):
    score = 0
    pwd_sign = [False for _ in range(4)]
    pwd_types = [string.ascii_uppercase, string.ascii_lowercase, string.digits, string.punctuation]
    pwd_dict = dict.fromkeys(pwd_types, 0)

    for s in pwd:
        for key in pwd_dict.keys():
            if s in key:
                pwd_dict[key] += 1
    if pwd_dict[string.ascii_uppercase] > 0:
        score += 10
        pwd_sign[0] = True
    if pwd_dict[string.ascii_uppercase] > 0:
        score += 10
        pwd_sign[1] = True
    if pwd_dict[string.digits] >= 1:
        score += 10
        pwd_sign[2] = True
        if pwd_dict[string.digits] > 1:
            score += 10
    if pwd_dict[string.punctuation] >= 1:
        score += 10
        pwd_sign[3] = True
        if pwd_dict[string.punctuation] > 1:
            score += 15

    if pwd_sign[0]&nbs***bsp;pwd_sign[1]:
        if pwd_sign[1]:
            score += 2
        if pwd_sign[2]:
            score += 1
        if all(pwd_sign):
            score += 1
    # length
    pwd_length = len(pwd)
    if pwd_length < 5:
        score += 5
    elif pwd_length <= 7:
        score += 10
    else:
        score += 25

    if score >= 90:
        print('VERY_SECURE')
    elif 80 <= score < 90:
        print('SECURE')
    elif 70 <= score < 80:
        print('VERY_STRONG')
    elif 60 <= score < 70:
        print('STRONG')
    elif 50 <= score < 60:
        print('AVERAGE')
    elif 25 <= score < 50:
        print('WEAK')
    else:
        print('VERY_WEAK')


if __name__ == '__main__':
    for line in sys.stdin:
        check_passwd(line)

发表于 2020-07-03 00:45:18 回复(0)
import java.util.Scanner;
public class Main {
    public static void getLevel(int score){
        if (score>=90){
            System.out.println("VERY_SECURE");
        }else if (score>=80){
            System.out.println("SECURE");
        }else if (score>=70){
            System.out.println("VERY_STRONG");
        }else if (score>=60){
            System.out.println("STRONG");
        }else if (score>=50){
            System.out.println("AVERAGE");
        }else if (score>=25){
            System.out.println("WEAK");
        }else if (score>=0){
            System.out.println("VERY_WEAK");
        }
    }
    public static int judgeRule(String str){
        int score = 0;
        char[] chars = str.toCharArray();
        //密码长度计分
        if (str.length()>=8){
            score += 25;
        }else if (str.length()>=5){
            score +=10;
        }else {
            score +=5;
        }
        //字母、数字、符号出现情况计分
        int upperCount = 0;
        int lowerCount = 0;
        int numberCount = 0;
        int symbolCount = 0;
        for (int i = 0; i < chars.length; i++) {
            if (Character.isLetter(chars[i])){
                if (Character.isUpperCase(chars[i])){
                    upperCount++;
                }else {
                    lowerCount++;
                }
            }else if (Character.isDigit(chars[i])){
                numberCount++;
            }else {
                symbolCount++;
            }
        }
        if (upperCount != 0 && lowerCount !=0){
            score +=20;
        }
        if (upperCount == str.length() || lowerCount == str.length()){
            score +=10;
        }
        if (numberCount>1){
            score +=20;
        }else if (numberCount ==1){
            score +=10;
        }
        if (symbolCount>1){
            score +=25;
        }else if (symbolCount ==1){
            score +=10;
        }
        //奖励计分
        if (upperCount!=0 && lowerCount !=0 && numberCount !=0 && symbolCount != 0){
            score +=5;
        }
        if ((upperCount == str.length() || lowerCount == str.length()) && numberCount !=0){
            score +=3;
        }
        if ((upperCount + lowerCount !=0 && numberCount !=0)){
            score +=2;
        }
        return score;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String str = sc.next();
            getLevel(judgeRule(str));
        }
    }
}

发表于 2020-02-19 17:51:45 回复(0)
//题目是很简单的,就是要注意细节,真的很容易错,条件太多了,要仔细
#include<iostream>
#include<cstring>
using namespace std;
int main(){
    char ch[500];
    while(cin>>ch){
        int len=strlen(ch),score=0,da=0,xiao=0,num=0,sign=0;
        if(len<=4) score=5;
        else if(len>=5&&len<=7) score=10;
        else score=25;
        for(int i=0;i<len;i++){
            if(ch[i]>='a'&&ch[i]<='z')
                xiao++;
            else if(ch[i]>='A'&&ch[i]<='Z')
                da++;
            else if(ch[i]>='0'&&ch[i]<='9')
                num++;
            else sign++;
        }
        if(da>0) score+=10;
        if(xiao>0) score+=10;
        if(num==1) score+=10;
        else if(num>1) score+=20;
        if(sign==1) score+=10;
        else if(sign>1) score+=25;
        if((da>0&&num>0)||(xiao>0&&num>0)){
            score+=2;
            if(sign>0){
                score+=1;
                if(da>0&&num>0&&xiao>0)
                    score+=2;
            }
        }
        if(0<=score&&score<25)
            cout<<"VERY_WEAK"<<endl;
        else if(25<=score&&score<50)
            cout<<"WEAK"<<endl;
        else if(50<=score&&score<60)
            cout<<"AVERAGE"<<endl;
        else if(60<=score&&score<70)
            cout<<"STRONG"<<endl;
        else if(70<=score&&score<80)
            cout<<"VERY_STRONG"<<endl;
        else if(80<=score&&score<90)
            cout<<"SECURE"<<endl;
        else if(90<=score)
            cout<<"VERY_SECURE"<<endl;
    }
}


发表于 2020-01-09 20:30:38 回复(0)