华为OJ 初级:密码强度等级
来源:互联网 发布:怎样安装windows 编辑:程序博客网 时间:2024/05/08 23:33
输入一个string的密码
输出密码等级
/*分为五个部分,分别计算每部分的得分,最后加起来 * 使用正则表达式判断 * */import java.util.Scanner;import java.util.regex.Matcher;import java.util.regex.Pattern;public class Main{public static void main(String[] args) {Scanner sc = new Scanner(System.in);String input = sc.next().trim();sc.close();int lengthScore = lengthScore(input);int charScore = charScore(input);int numScore = numScore(input);int fuhaoScore = fuhaoScore(input);int awardScore = awardScore(input);int sum = lengthScore + charScore+numScore+fuhaoScore+awardScore;String output = null;if(sum >= 0)output = "VERY_WEAK";if(sum >= 25)output = "WEAK";if(sum >= 50)output = "AVERAGE";if(sum >= 60)output = "STRONG";if(sum >= 70)output = "VERY_STRONG";if(sum >= 80)output = "SECURE";if(sum >= 90)output = "VERY_SECURE ";System.out.println(output);}private static int lengthScore(String input) {int score = 0;if (input.length() >= 8)score = 25;else if (input.length() <= 4)score = 5;elsescore = 10;return score;}private static int charScore(String input) {int score = 0;Pattern pattern = Pattern.compile("[a-zA-Z]");Matcher matcher;int flag = 0;String[] string = input.trim().split("");for (int i = 0; i < string.length; i++) {matcher = pattern.matcher(string[i]);if (matcher.matches())flag++;}if (flag != 0) {if (input.toLowerCase().equals(input))score = 10;elsescore = 20;} elsescore = 0;return score;}private static int numScore(String input) {int score = 0;Pattern pattern = Pattern.compile("[0-9]");Matcher matcher;int flag = 0;String[] string = input.trim().split("");for (int i = 0; i < string.length; i++) {matcher = pattern.matcher(string[i]);if (matcher.matches())flag++;}if (flag != 0) {if (flag > 1)score = 20;elsescore = 10;} elsescore = 0;return score;}private static int fuhaoScore(String input) {int score = 0;Pattern pattern = Pattern.compile(".*[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#&*()&;—|{}‘;:”“'。,、?].*");Matcher matcher;int flag = 0;String[] string = input.trim().split("");for (int i = 0; i < string.length; i++) {matcher = pattern.matcher(string[i]);if (matcher.matches())flag++;}if (flag != 0) {if (flag > 1)score = 25;elsescore = 10;} elsescore = 0;return score;}private static int awardScore(String input) {int score = 0;if(numScore(input) > 0 && charScore(input) > 0){score = 2;if(fuhaoScore(input) > 0){score = 3;if(charScore(input) == 20)score = 5;}}return score;}}
0 0
- 华为OJ 初级:密码强度等级
- 华为oj初级 密码强度等级
- 华为OJ-密码强度等级
- 【华为oj】密码强度等级
- 华为oj 密码强度等级
- 华为oj 密码强度等级
- 【华为 OJ 】密码强度等级
- 【华为OJ】密码强度等级
- 华为OJ(密码强度等级)
- 【华为OJ】【086-密码强度等级】
- 华为OJ——密码强度等级
- 华为OJ——密码强度等级
- 华为OJ——密码强度等级
- OJ-----密码强度等级
- 华为OJ训练之0034-170112-密码强度等级
- 华为机试:密码强度等级、百钱买百鸡问题
- 密码强度等级
- 密码强度等级
- 解决GridView控件分页点击两次问题
- Thrift 快速入门
- Linux下gcc编译动态链接库
- Concurrent and Parallel Programming
- Docker DockerFile指令
- 华为OJ 初级:密码强度等级
- 嵌入式开发第16天(开发板触摸驱动,mmap)
- git 与 svn 的主要区别!
- 大数据Spark “蘑菇云”行动前传第10课:Scala继承彻底实战和Spark源码鉴赏.
- PHP实现多文件上传
- Oracle的存储架构
- C语言中的数据类型
- bootstrap-table使用总结
- 爬虫系统简介