题解 | #密码强度等级#
密码强度等级
http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine()){
System.out.println(getResult(sc.nextLine()));
}
sc.close();
}
public static String getResult(String str){
int length = 0;
int letter = 0;
int dig = 0;
int noletdig = 0;
int combine = 0;
//长度判断
if(str.length()>=8){
length=25;
}else if(str.length()>=5){
length=10;
}else{
length=5;
}
int isLow = 0;
int isUpp = 0;
int isDig = 0;
int noLettOrDig = 0;
for(int i = 0;i<str.length();i++){
char c = str.charAt(i);
if(Character.isLowerCase(c)){
isLow++;
}
if(Character.isUpperCase(c)){
isUpp++;
}
if(Character.isDigit(c)){
isDig++;
}
if(!Character.isLetterOrDigit(c)){
noLettOrDig++;
}
}
if(isLow>0 && isUpp>0){
letter = 20;
}else if(isLow>0 || isUpp>0){
letter = 10;
}else{
letter = 0;
}
if(isDig==0){
dig = 0;
}else if(isDig==1){
dig = 10;
}else{
dig = 20;
}
if(noLettOrDig>1){
noletdig = 25;
}else if(noLettOrDig>0){
noletdig = 10;
}else{
noletdig = 0;
}
if(noLettOrDig>1){
noletdig = 25;
}else if(noLettOrDig>0){
noletdig = 10;
}else{
noletdig = 0;
}
if(letter == 20 && dig > 0 && noletdig > 0){
combine = 5;
}else if(letter == 10 && dig > 0 && noletdig > 0){
combine = 3;
}else if(letter == 10 && dig > 0){
combine = 2;
}else{
combine = 0;
}
String output ="";
int res = length + letter + dig + noletdig + combine;
if(res>=90){
output ="VERY_SECURE";
}else if(res>=80){
output ="SECURE";
}else if(res>=70){
output ="VERY_STRONG";
}else if(res>=60){
output ="STRONG";
}else if(res>=50){
output ="AVERAGE";
}else if(res>=25){
output ="WEAK";
}else{
output ="VERY_WEAK";
}
return output;
}
}
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine()){
System.out.println(getResult(sc.nextLine()));
}
sc.close();
}
public static String getResult(String str){
int length = 0;
int letter = 0;
int dig = 0;
int noletdig = 0;
int combine = 0;
//长度判断
if(str.length()>=8){
length=25;
}else if(str.length()>=5){
length=10;
}else{
length=5;
}
int isLow = 0;
int isUpp = 0;
int isDig = 0;
int noLettOrDig = 0;
for(int i = 0;i<str.length();i++){
char c = str.charAt(i);
if(Character.isLowerCase(c)){
isLow++;
}
if(Character.isUpperCase(c)){
isUpp++;
}
if(Character.isDigit(c)){
isDig++;
}
if(!Character.isLetterOrDigit(c)){
noLettOrDig++;
}
}
if(isLow>0 && isUpp>0){
letter = 20;
}else if(isLow>0 || isUpp>0){
letter = 10;
}else{
letter = 0;
}
if(isDig==0){
dig = 0;
}else if(isDig==1){
dig = 10;
}else{
dig = 20;
}
if(noLettOrDig>1){
noletdig = 25;
}else if(noLettOrDig>0){
noletdig = 10;
}else{
noletdig = 0;
}
if(noLettOrDig>1){
noletdig = 25;
}else if(noLettOrDig>0){
noletdig = 10;
}else{
noletdig = 0;
}
if(letter == 20 && dig > 0 && noletdig > 0){
combine = 5;
}else if(letter == 10 && dig > 0 && noletdig > 0){
combine = 3;
}else if(letter == 10 && dig > 0){
combine = 2;
}else{
combine = 0;
}
String output ="";
int res = length + letter + dig + noletdig + combine;
if(res>=90){
output ="VERY_SECURE";
}else if(res>=80){
output ="SECURE";
}else if(res>=70){
output ="VERY_STRONG";
}else if(res>=60){
output ="STRONG";
}else if(res>=50){
output ="AVERAGE";
}else if(res>=25){
output ="WEAK";
}else{
output ="VERY_WEAK";
}
return output;
}
}