密码

网上流传一句话:"常在网上飘啊,哪能不挨刀啊~"。其实要想能安安心心地上网其实也不难,学点安全知识就可以。

首先,我们就要设置一个安全的密码。那什么样的密码才叫安全的呢?一般来说一个比较安全的密码至少应该满足下面两个条件:

(1).密码长度大于等于8,且不要超过16。
(2).密码中的字符应该来自下面“字符类别”中四组中的至少三组。

这四个字符类别分别为:
1.大写字母:A,B,C...Z;
2.小写字母:a,b,c...z;
3.数字:0,1,2...9;
4.特殊符号:~,!,@,#,$,%,^;

给你一个密码,你的任务就是判断它是不是一个安全的密码。
Input输入数据第一行包含一个数M,接下有M行,每行一个密码(长度最大可能为50),密码仅包括上面的四类字符。Output对于每个测试实例,判断这个密码是不是一个安全的密码,是的话输出YES,否则输出NO。Sample Input
3
a1b2c3d4
Linle@ACM
^~^@^@!%
Sample Output
NO
YES
NO
AC程序

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<ctype.h>
#include<stack>
#include<math.h>
#include <string>
#include<algorithm>
const int N = 51;
using namespace std;
char str[N];
int main()
{
    int M;
    cin>>M;
    while(M--)
    {
        int Da,Xiao,Shu,Fuhao;
        Da = Xiao = Shu = Fuhao = 0;
        int len = 0;
        memset(str, '\0',sizeof(str));
        cin>>str;
        len = strlen(str);
        if(len > 16 || len < 8)
            printf("NO\n");
        else
        {
            for(int i = 0; i < len;i++)
            {
                if(str[i] >= 'A' && str[i] <= 'Z')
                    Da = 1;
                else if(str[i] >= 'a' && str[i] <= 'z')
                    Xiao = 1;
                else if(str[i] >= '0' && str[i] <= '9')
                    Shu = 1;
                else
                    Fuhao = 1;
            }
            if(Da + Xiao + Shu + Fuhao >= 3)
                printf("YES\n");
            else
                printf("NO\n");
        }

    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值