安全密码(模拟)

纯模拟题,以及考察对于字符串的处理,有实现的细节需要注意,以及记住几个常用的函数方便写代码

首先可以先判断密码的长度如果<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;
    
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值