题解 | #密码强度等级#
密码强度等级
http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
String str = sc.next();
int res = 0;
if ((zi(str) > 0 && zi(str) <= 10) && shu(str) > 0) {
res = 2;
} else if ((zi(str) > 0 && zi(str) <= 10) && shu(str) > 0 && fu(str) > 0) {
res = 3;
} else if (zi(str) == 20 && shu(str) > 0 && fu(str) > 0) {
res = 5;
}
res = res + chang(str) + zi(str) + shu(str) + fu(str);
if (res >= 90) {
System.out.println("VERY_SECURE");
} else if (res >= 80) {
System.out.println("SECURE");
} else if (res >= 70) {
System.out.println("VERY_STRONG");
} else if (res >= 60) {
System.out.println("STRONG");
} else if (res >= 50) {
System.out.println("AVERAGE");
} else if (res >= 25) {
System.out.println("WEAK");
} else if (res >= 0) {
System.out.println("VERY_WEAK");
}
}
}
public static int chang(String str){
int num = 0;
if (str.length() <= 4){
num = 5;
}else if(str.length() >= 5 && str.length() <= 7){
num = 10;
}else if (str.length() >= 8){
num = 25;
}
return num;
}
public static int zi(String str){
int num = 0;
int count1 = 0;
int count2 = 0;
for (int i = 0; i < str.length(); i++){
char c = str.charAt(i);
if(c >= 'a' && c <= 'z'){
count1++;
}else if(c >= 'A' && c <= 'Z'){
count2++;
}
}
if(count1 == 0 && count2 == 0){
num = 0;
}else if((count1 > 0 && count2 == 0) || (count1 == 0 && count2 > 0)){
num = 10;
}else if (count1 > 0 && count2 > 0){
num = 20;
}
return num;
}
public static int shu(String str){
int num = 0;
int count = 0;
for (int i = 0; i < str.length(); i++){
char c = str.charAt(i);
if(c >= '0' && c <= '9'){
count++;
}
}
if (count == 0){
num = 0;
}else if(count == 1){
num = 10;
}else if(count > 1){
num = 20;
}
return num;
}
public static int fu(String str){
int count = 0;
int num = 0;
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c >= 33 && c <= 47) {
count++;
}else if(c >= 58 && c <= 64) {
count++;
}else if(c >= 91 && c <= 96) {
count++;
}else if(c >= 123 && c <= 126) {
count++;
}
}
if (count == 0){
num = 0;
}else if (count == 1){
num = 10;
}else if (count > 1){
num = 25;
}
return num;
}
}