pat乙1081 检查密码

#include<iostream>
using namespace std;
int main()

{
    int i,j,n,len,hasnum,hasword,hasother;
    string str;
    cin>>n;
    char c=getchar();//接收第一个换行符
    for(i=0;i<n;i++)
    {
       // cin>>str;
        getline(cin,str);//字符串中可能有空格等
        hasnum=0;//赋初值
        hasword=0;
        hasother=0;
        if(str.length()<6)//如果密码过短,直接输出,进行下次循环
        {
            cout<<"Your password is tai duan le."<<endl;
            continue;
        }
        for(j=0;j<str.length();j++)//遍历密码,查看数字,字母,非法字符的出现情况
        {
            if(str[j]>='a'&&str[j]<='z')hasword=1;
            else if(str[j]>='A'&&str[j]<='Z')hasword=1;
            else if(str[j]>='0'&&str[j]<='9')hasnum=1;
            else if(str[j]=='.')
            {

            }
            else hasother=1;
        }
        if(hasother)//有非法字符
        {
            cout<<"Your password is tai luan le."<<endl;
        }
        else
        {
            if(hasword&&hasnum)//合法密码
            {
                cout<<"Your password is wan mei."<<endl;
            }
            else if(hasword&&!hasnum)//无数字
            {
                cout<<"Your password needs shu zi."<<endl;
            }
            else if(!hasword&&hasnum)//无字母
            {
                cout<<"Your password needs zi mu."<<endl;
            }
            else//似乎并没有全是......的测试点
            {
                //cout<<"Your password needs shu zi.Your password needs zi mu."<<endl;
            }
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值