本題要求你幫助某網站的使用者注冊子產品寫一個密碼合法性檢查的小功能。該網站要求使用者設定的密碼必須由不少于6個字元組成,并且隻能有英文字母、數字和小數點
.
,還必須既有字母也有數字。
輸入格式:
輸入第一行給出一個正整數 N(≤ 100),随後 N 行,每行給出一個使用者設定的密碼,為不超過 80 個字元的非空字元串,以回車結束。
注意: 題目保證不存在隻有小數點的輸入。
輸出格式:
- 如果密碼合法,輸出
;Your password is wan mei.
- 如果密碼太短,不論合法與否,都輸出
;Your password is tai duan le.
- 如果密碼長度合法,但存在不合法字元,則輸出
;Your password is tai luan le.
- 如果密碼長度合法,但隻有字母沒有數字,則輸出
;Your password needs shu zi.
- 如果密碼長度合法,但隻有數字沒有字母,則輸出
。Your password needs zi mu.
輸入樣例:
5
123s
zheshi.wodepw
1234.5678
WanMei23333
pass*word.6
輸出樣例:
Your password is tai duan le.
Your password needs shu zi.
Your password needs zi mu.
Your password is wan mei.
Your password is tai luan le.
代碼實作:
import java.io.*;
import java.util.Locale;
/**
* @author yx
* @date 2022-07-26 13:09
*/
public class Main {
static PrintWriter out=new PrintWriter(System.out);
static BufferedReader ins=new BufferedReader(new InputStreamReader(System.in));
static StreamTokenizer in=new StreamTokenizer(ins);
public static void main(String[] args) throws IOException {
in.nextToken();
int N = (int) in.nval;
for (int j = 0; j < N; j++) {
char[] arr = ins.readLine().toUpperCase(Locale.ROOT).toCharArray();
int length = arr.length;
int zm_no = 0;
int sz_no = 0;
int dian_no = 0;
int bhf_no = 0;
for (int i = 0; i < length; i++) {
if ((arr[i] >= 'A' && arr[i] <= 'Z')) {
zm_no++;
} else if ((arr[i] >= '0' && arr[i] <= '9')) {
sz_no++;
} else if (arr[i] == '.') {
dian_no++;
} else {
bhf_no++;
}
}
int length_no = dian_no + sz_no + zm_no;
if (length_no >= 6) {//長度合法
if (bhf_no > 0) {
System.out.println("Your password is tai luan le.");
} else if (sz_no == 0) {
System.out.println("Your password needs shu zi.");
} else if (zm_no == 0) {
System.out.println("Your password needs zi mu.");
}else {
System.out.println("Your password is wan mei.");
}
} else {
System.out.println("Your password is tai duan le.");
}
}
}
}