本題要求你幫助某網站的用戶注冊模塊寫一個密碼合法性檢查的小功能。該網站要求用戶設置的密碼必須由不少于6個字符組成,并且只能有英文字母、數字和小數點?.
,還必須既有字母也有數字。
輸入格式:
輸入第一行給出一個正整數 N(≤?100),隨后 N 行,每行給出一個用戶設置的密碼,為不超過 80 個字符的非空字符串,以回車結束。
輸出格式:
對每個用戶的密碼,在一行中輸出系統反饋信息,分以下5種:
- 如果密碼合法,輸出
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.
#include<iostream> using namespace std; const int maxn = 110;int main(){int n;cin >> n;string s;getchar();while(n--){getline(cin,s);//cin >> s;bool tag[4] = {false};if(s.length() < 6){cout << "Your password is tai duan le." << endl;continue;}for(int i = 0; i < s.length(); i++){if(s[i] >= '0' && s[i] <= '9')tag[0] = true;else if((s[i] >= 'a' && s[i] <= 'z')||(s[i] >= 'A' && s[i] <= 'Z')) tag[1] = true;else if(s[i] == '.') tag[2] = true;else tag[3] = true;}if(tag[3]) cout <<"Your password is tai luan le." << endl;//tag[0] == 1表示有數字,tag[1] == 1表示有字母 else if(tag[1] == false) cout <<"Your password needs zi mu." << endl;else if(tag[0] == false)cout << "Your password needs shu zi." << endl;else cout <<"Your password is wan mei." << endl;for(int i = 0 ; i < 4; i++) tag[i] = false;}return 0; }
?