PAT(Basic Level) Practice : 1081 检查密码 (15分)

1081 检查密码 (15分)

测试点2的坑

输入的密码可能有空格
解决:用getline一行一行读取
先getline一行,把第一行的数字n吃掉

代码

#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
//scanf printf防止超时
#include <algorithm>
//vector的sort
#include <sstream>
//转换
using namespace std;

#include<iomanip>
//精度

#include<cmath>
//round四舍五入取整
#include <map>


bool judge1(string str)
{
    bool flag=true;
    for(int i=0;i<str.size();i++)
    {
        if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z')||str[i]=='.'||(str[i]>='0'&&str[i]<='9'))
        {

        }else
        {
            flag=false;
        }
    }
    return flag;
}


int main()
{
    int n;
    cin>>n;string str;
        getline(cin,str);
    for(int i=0;i<n;i++)
    {
        getline(cin,str);
        int count1=0;
        int count2=0;
        for(int i=0;i<str.length();i++)
        {
            if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z'))
                count1++;
            if(str[i]>='0'&&str[i]<='9')
                count2++;
        }
        if(str.length()<6)
            cout<<"Your password is tai duan le."<<endl;
        else if(!judge1(str))
        {
            cout<<"Your password is tai luan le."<<endl;
        }else if(count2==0)
        {
            cout<<"Your password needs shu zi."<<endl;
        }else if(count1==0)
        {
            cout<<"Your password needs zi mu."<<endl;
        }else
        {
            cout<<"Your password is wan mei."<<endl;
        }
    }
    return 0;
}

posted @ 2020-09-30 22:42  韩天尊  阅读(116)  评论(0)    收藏  举报