纯模拟题,以及考察对于字符串的处理,有实现的细节需要注意,以及记住几个常用的函数方便写代码
首先可以先判断密码的长度如果<8了直接continue了,其次才是判断是否满足条件
条件有四个,大小字母,数字,以及其他,关于大小写字母和数字我们其实是有一个判断函数的不需要自己再去实现了,判断大写字母是 isupper()函数,小写字母是islower(),数字是isdigit(),还有一个函数是判断是否是字母的就是没有分的那么细 isalpha()
#include<iostream>
using namespace std;
string s;
int main()
{
while(cin>>s)
{
bool uppers=false,lowers=false,digits=false,others=false;
int count=0;
if(s.size()<8)
{
cout<<"NO"<<endl;
continue;
}
for(int i=0;i<s.size();i++)
{
if(isupper(s[i]))uppers=true;
else if(islower(s[i]))lowers=true;
else if(isdigit(s[i]))digits=true;
else others=true;
}
if(uppers==true)count++;
if(lowers==true)count++;
if(digits==true)count++;
if(others==true)count++;
if(count>=3)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}