HDU 2043 密码

http://acm.hdu.edu.cn/showproblem.php?pid=2043

Problem Description

网上流传一句话:"常在网上飘啊,哪能不挨刀啊~"。其实要想能安安心心地上网其实也不难,学点安全知识就可以。
首先,我们就要设置一个安全的密码。那什么样的密码才叫安全的呢?一般来说一个比较安全的密码至少应该满足下面两个条件:
(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

 代码:

#include <bits/stdc++.h>

using namespace std;

char s[111];
int len;
int A()
{
    for(int i=0; i<len; i++)
    {
        if(s[i]>='a'&&s[i]<='z')
            return 2;
        else
            continue;
    }
    return 1;
}
int B()
{
    for(int i=0; i<len; i++)
    {
        if(s[i]>='A'&&s[i]<='Z')
            return 2;
        else
            continue;
    }
    return 1;
}
int C()
{
    for(int i=0; i<len; i++)
    {
        if(s[i]=='~'||s[i]=='!'||s[i]=='@'||s[i]=='#'||s[i]=='$'||s[i]=='%'||s[i]=='^')
            return 2;
        else
            continue;
    }
    return 1;
}
int D()
{
    for(int i=0; i<len; i++)
    {
        if(s[i]>='0'&&s[i]<='9')
            return 2;
        else
            continue;
    }
    return 1;
}
int main()
{
    int m;
    cin>>m;
    for(int i=1; i<=m; i++)
    {
        int sum=1;
        scanf("%s",s);
        len = strlen(s);
        sum=A()*B()*C()*D();
        //cout<<A()<<B()<<C()<<D()<<sum<<endl;
        if(sum>=8&&len>=8&&len<16)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/zlrrrr/p/9221857.html