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 <iostream>
#include <string>
using namespace std;
bool f(string str,char a,char b)
{
bool flag=false;
int n=str.length();
for(int i=;i<n;i++){
if(str[i]>=a&&str[i]<=b){
flag=true;
break;
}
}
return flag;
}
bool g(string str)
{
bool flag=false;
int n=str.length();
for(int i=;i<n;i++){
if(str[i]==':'||str[i]=='~'||str[i]=='!'||str[i]=='@'||str[i]=='#'||str[i]=='$'||str[i]=='%'||str[i]=='^'){
flag=true;
break;
}
}
return flag;
}
int main()
{
int n,k=,p;
string str;
cin>>n;
while(k<n){
p=;
cin>>str;
int n=str.length();
if(n>=&&n<=){
if(f(str,'A','Z'))p++;
if(f(str,'a','z'))p++;
if(f(str,'',''))p++;
if(g(str))p++;
if(p>=)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
else cout<<"NO"<<endl;
k++;
}
//system("pause");
return ;
}

Q - 密码(第二季水)的更多相关文章

  1. D - Counterfeit Dollar(第二季水)

    Description Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are t ...

  2. F - The Fun Number System(第二季水)

    Description In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight o ...

  3. N - Robot Motion(第二季水)

    Description A robot has been programmed to follow the instructions in its path. Instructions for the ...

  4. S - 骨牌铺方格(第二季水)

    Description          在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数.         例如n=3时,为2× 3方格,骨牌的铺放方案有三种, ...

  5. R - 一只小蜜蜂...(第二季水)

    Description          有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数.         其中,蜂房的结构如下所示.     ...

  6. I - Long Distance Racing(第二季水)

    Description Bessie is training for her next race by running on a path that includes hills so that sh ...

  7. V - 不容易系列之(4)――考新郎(第二季水)

    Description          国庆期间,省城HZ刚刚举行了一场盛大的集体婚礼,为了使婚礼进行的丰富一些,司仪临时想出了有一个有意思的节目,叫做"考新郎",具体的操作是这 ...

  8. Y - Design T-Shirt(第二季水)

    Description Soon after he decided to design a T-shirt for our Algorithm Board on Free-City BBS, XKA ...

  9. B - Maya Calendar(第二季水)

    Description During his last sabbatical, professor M. A. Ya made a surprising discovery about the old ...

随机推荐

  1. VS 2003 无法打开Web项目 文件路径与URL不符 这两者需要映射到相同的服务器位置

    解决方法: 将C:\Documents   and   Settings\Administrator\VSWebCache下面的文件全部删除

  2. WCF入门教程系列三

    一.WCF服务应用程序与WCF服务库 我们在平时开发的过程中常用的项目类型有“WCF 服务应用程序”和“WCF服务库”. WCF服务应用程序,是一个可以执行的程序,它有独立的进程,WCF服务类契约的定 ...

  3. javaScript给元素添加多个class

    <html> <head> <style type="text/css"> .div2{ font-size:16px; color:orang ...

  4. PROCEDURE_监测系统_告警信息存储过程—产生告警信息插入告警表

    create or replace procedure proc_alarmlog(in_id   in number, --采集器编码                                 ...

  5. Javascript经典实例 - 字符串

    1] 'this is a string'这是字符串直接量,new String('this is a string')这是字符串对象,字符串对象可以用字符串对象所带的属性和方法,直接量在“表面上”也 ...

  6. IIS6.0架构概览(翻译)

    IIS6.0提供一个重新设计的万维网发布服务(World Wide Web Publishing Service)架构,可以帮助你为你的网站构建更好的性能.可靠.可扩展性(scalability),无 ...

  7. 工作中小知识点汇总(c#)

    1.OOP 实体与数据库字段转换(注意 此时实体字段必须和数据库中查询的字段列名相同) list = ModelExtend.GetByDataTablePart<EZRate>(ds.T ...

  8. Git学习05 --分支管理02

    1.冲突 产生冲突后,查看readme.txt   可以看到冲突内容 <<<<<<< ======= >>>>>>> ...

  9. Code First 创建数据库

    最近在对以前学的知识做一个总结,EF 这块,Code First 是很重要的一部分,方便快捷创建模型.   Code First有两种配置方式: DataAnnatation: [Table(&quo ...

  10. poj 3164 Command Network

    http://poj.org/problem?id=3164 第一次做最小树形图,看着别人的博客写,还没弄懂具体的什么意思. #include <cstdio> #include < ...