zoukankan      html  css  js  c++  java
  • 杭电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
    我的AC code
    #include<stdio.h>
    #include<string.h>
    int main()
    {
     int n,i,k,f1,f2,f3,f4,f;
     char str[20];
     scanf("%d",&n);
     getchar();
     while(n--)
     {   f1=0;
     f2=0;
     f3=0;
     f4=0;
      gets(str);
           k=strlen(str);
        if(k>16||k<8)
        {  printf("NO\n");
        continue;
        }
        for(i=0;i<k;i++)
        {
         if(str[i]>='A'&&str[i]<='Z')
                   f1=1;
         if(str[i]>='a'&&str[i]<='z')
          f2=1;
         if(str[i]>='0'&&str[i]<='9')
          f3=1;
         if(str[i]=='~'||str[i]=='!'||str[i]=='@'||str[i]=='#'||str[i]=='$'||str[i]=='%'||str[i]=='^')
          f4=1;
        }
        f=f1+f2+f3+f4;
        if(f>=3)
         printf("YES\n");
        else
         printf("NO\n");
        }
        return 0;
        }
  • 相关阅读:
    [转]批处理for命令使用指南
    批处理命令学习
    【树】Count Complete Tree Nodes
    【树】Flatten Binary Tree to Linked List(先序遍历)
    【树】Kth Smallest Element in a BST(递归)
    巧用border特性实现聊天气泡效果
    【树】Lowest Common Ancestor of a Binary Tree(递归)
    【树】Path Sum II(递归)
    【树】Populating Next Right Pointers in Each Node
    【树】Serialize and Deserialize Binary Tree
  • 原文地址:https://www.cnblogs.com/ruanwenming/p/2535151.html
Copyright © 2011-2022 走看看