java題目HJ87 密碼強度等級
阿新 • • 發佈:2022-03-06
描述
密碼按如下規則進行計分,並根據不同的得分為密碼進行安全等級劃分。
一、密碼長度:
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_SECURE
SECURE
VERY_STRONG
STRONG
AVERAGE
WEAK
VERY_WEAK
請根據輸入的密碼字串,進行安全評定。
注:
字母:a-z,A-Z
數字:0-9
符號包含如下:(ASCII碼錶可以在UltraEdit的選單view->ASCIITable檢視)
!"#$%&'()*+,-./(ASCII碼:0x21~0x2F)
:;<=>?@(ASCII碼:0x3A~0x40)
[\]^_`(ASCII碼:0x5B~0x60)
{|}~(ASCII碼:0x7B~0x7E)
輸入描述:
本題含有多組輸入樣例。
每組樣例輸入一個string的密碼
輸出描述:
每組樣例輸出密碼等級
示例1
輸入:38$@NoNoNo 123輸出:
VERY_SECURE WEAK說明:
第一組樣例的密碼長度大於等於8個字元,得25分;大小寫字母都有所以得20分;有兩個數字,所以得20分;包含大於1符號,所以得25分;由於該密碼包含大小寫字母、數字和符號,所以獎勵部分得5分,經統計得該密碼的密碼強度為25+20+20+25+5=95分。 同理,第二組樣例密碼強度為5+0+20+0+0=25分。
示例2
輸入:Jl)M:+輸出:
AVERAGE說明:
示例2的密碼強度為10+20+0+25+0=55分。
1 import java.io.*; 2 import java.util.*; 3 4 public class Main { 5 public static void main(String[] args) throws IOException { 6 BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 7 String origin = null; 8 while((origin = br.readLine()) != null) { 9 int score = 0; 10 int number= 0; 11 int lower = 0; 12 int upper = 0; 13 int symbol = 0; 14 15 char[] ch = origin.toCharArray(); 16 for(int i =0; i < ch.length; i++) { 17 if (ch[i] >= '0' && ch[i] <= '9') 18 number++; 19 else if(ch[i] >= 'A' && ch[i] <= 'Z') 20 upper++; 21 else if(ch[i] >= 'a' && ch[i] <= 'z') 22 lower++; 23 else 24 symbol++; 25 } 26 //長度判斷 27 if(ch.length <=4) { 28 score = score + 5; 29 } else if(ch.length <=7 && ch.length >= 5) { 30 score = score + 10; 31 } else { 32 score = score + 25; 33 } 34 35 //字母判斷 36 if(upper == 0 && lower == 0) 37 score = score + 0; 38 else if (upper != 0 && lower != 0) 39 score = score + 20; 40 else 41 score = score + 10; 42 43 //數字判斷 44 if(number == 1) 45 score = score + 10; 46 else if( number > 1) 47 score = score + 20; 48 else 49 score = score + 0; 50 51 if(symbol == 1) 52 score = score + 10; 53 else if( symbol > 1) 54 score = score + 25; 55 else 56 score = score + 0; 57 58 if(upper != 0 && lower != 0 && number != 0 && symbol != 0) 59 score = score +5; 60 else if(number != 0 && symbol != 0 && (upper != 0 || lower != 0)) 61 score = score + 3; 62 else 63 score = score +2; 64 65 if( score >= 90) 66 System.out.println("VERY_SECURE"); 67 else if( score >= 80 && score <90) 68 System.out.println("SECURE"); 69 else if( score >= 70 && score <80) 70 System.out.println("VERY_STRONG"); 71 else if( score >= 60 && score <70) 72 System.out.println("STRONG"); 73 else if( score >= 50 && score <60) 74 System.out.println("AVERAGE"); 75 else if( score >= 25 && score <50) 76 System.out.println("WEAK"); 77 else if( score >= 0 && score <25) 78 System.out.println("VERY_WEAK"); 79 } 80 } 81 }