题目链接:请点击
isalpha() 用于判断是否是字母,头文件cctype
isdigit() 用于判断是否是数字,头文件cctype
AC代码:
#include<iostream>
#include<cctype>
#include<cstring>
using namespace std;
int main(){
int N;
cin>>N;
getchar();//吸收空格
while(N--){
string pwd;
getline(cin,pwd);//读取一行 测点2中可能有空格
int illegal=0;
if(pwd.length()<6) cout<<"Your password is tai duan le."<<endl;
else{
int alpha=0,digit=0;//表示有无字母或数字
for(int i=0;i<pwd.length();i++){
if(isalpha(pwd[i])) alpha=1;
else if(isdigit(pwd[i])) digit=1;
else if(pwd[i]=='.') continue;
else {//有非法字符
illegal=1;
cout<<"Your password is tai luan le."<<endl;
break;
}
}
if(alpha==0&&digit==1&&illegal==0) cout<<"Your password needs zi mu."<<endl;
if(alpha==1&&digit==0&&illegal==0) cout<<"Your password needs shu zi."<<endl;
if(digit==1&&alpha==1&&illegal==0) cout<<"Your password is wan mei."<<endl;
}
}
return 0;
}