zoukankan      html  css  js  c++  java
  • hdu2043 密码



    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
     
       一道水题,一开始嫌麻烦没做,后来想到一个比较好的处理方法。还有注的是密码的长度8~16.
    AC Code:
     1 #include<iostream>
     2 #include<iomanip>
     3 #include<cstdio>
     4 #include<cstdlib>
     5 #include<cstring>
     6 #include<cmath>
     7 #include<string>
     8 #include<algorithm>
     9 #include<vector>
    10 #include<map>
    11 #include<stack>
    12 #include<queue>
    13 #include<deque>
    14 #include<set>
    15 #include<cctype>
    16 #define maxn (int)1e5
    17 #define INF 0x3f3f3f3f
    18 using namespace std;
    19 int main()
    20 {
    21     ios::sync_with_stdio(false);
    22     cin.tie(0);
    23     cout.tie(0);
    24     #ifndef ONLINE_JUDGE
    25     freopen("input.txt","r",stdin);
    26     #endif
    27    int T;
    28    set<char> st;
    29    st.insert('~'),st.insert('!'),st.insert('@'),st.insert('#'),st.insert('$'),st.insert('%'),st.insert('^');
    30    string s;
    31    cin>>T;
    32    while(T--)
    33    {
    34        cin>>s;
    35        int l=s.size();
    36        if(l<8||l>16) {
    37         cout<<"NO"<<endl;
    38         continue;
    39        }
    40        int num1=0,num2=0,num3=0,num4=0;
    41        for(int i=0;i<l;++i)
    42        {
    43            if(isdigit(s[i])) num1=1;
    44            if(isupper(s[i])) num2=1;
    45            if(isalpha(s[i])) {
    46             if(!isupper(s[i])) num3=1;
    47            }
    48            if(st.count(s[i])) num4=1;
    49 
    50        }
    51        if(num1+num2+num3+num4>=3) cout<<"YES"<<endl;
    52        else cout<<"NO"<<endl;
    53    }
    54 
    55 }
    View Code
  • 相关阅读:
    MySQL优化
    Java GC
    Java GC
    一致性哈希算法在分布缓存中的应用
    Hadoop
    Hbase 基础
    ORACLE
    ORACLE
    ORACLE
    ORACLE
  • 原文地址:https://www.cnblogs.com/Auroras/p/11183321.html
Copyright © 2011-2022 走看看