PTA-检查密码
本题要求你帮助某网站的用户注册模块写一个密码合法性检查的小功能。该网站要求用户设置的密码必须由不少于6个字符组成,并且只能有英文字母、数字和小数点 .,还必须既有字母也有数字。
输出格式:
对每个用户的密码,在一行中输出系统反馈信息,分以下5种:
如果密码合法,输出Your password is wan mei.;
如果密码太短,不论合法与否,都输出Your password is tai duan le.;
如果密码长度合法,但存在不合法字符,则输出Your password is tai luan le.;
如果密码长度合法,但只有字母没有数字,则输出Your password needs shu zi.;
如果密码长度合法,但只有数字没有字母,则输出Your password needs zi mu.。
输入样例:
5
123s
zheshi.wodepw
1234.5678
WanMei23333
pass*word.6
输出样例:
Your password is tai duan le.
Your password needs shu zi.
Your password needs zi mu.
Your password is wan mei.
Your password is tai luan le.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
getchar();
string passward;
while(n--)
{
int flag1=0,flag2=0,flag3=0,flag4=0;
getline(cin,passward);
if(passward.size() < 6)
cout<<"Your password is tai duan le."<<endl;
else
{
for(int i=0; i<passward.size(); i++)
{
if(passward[i] >= '0'&&passward[i] <= '9')
flag1 = 1;
else if((passward[i] >= 'a'&&passward[i] <= 'z') ||(passward[i] >= 'A'&&passward[i] <= 'Z'))
flag2 = 1;
else if(passward[i] == '.')
flag4 =1;
else
flag3 = 1;
}
if(flag3 == 1)
cout<<"Your password is tai luan le."<<endl;
else if(flag1==1&&flag2==1)
{
cout<<"Your password is wan mei."<<endl;
}
else if(flag1 == 1&&flag2==0)
cout<<"Your password needs zi mu."<<endl;
else if(flag1 == 0&&flag2 == 1)
cout<<"Your password needs shu zi."<<endl;
}
}
}
/*
#include <iostream>
#include<cstdio>
#include<string.h>
using namespace std;
int main(){
int N;
cin>>N;
getchar();
string password;
while(N--)
{
getline(cin,password);
int len=password.length();
if(len<6){
printf("Your password is tai duan le.\n");continue;
}
else{
int flag=1;int num=0;int letter=0;int success=0;
for(int i=0;password[i]!='\0';i++)
{
if(password[i]>='0'&&password[i]<='9')num=1;
else if((password[i]>='A'&&password[i]<='Z')||(password[i]>='a'&&password[i]<='z'))letter=1;
else if(password[i]!='.'){
flag=0; break;
}
}
if(flag==0)printf("Your password is tai luan le.\n");
else if(letter==0){printf("Your password needs zi mu.\n");flag=0;}
else if(num==0){printf("Your password needs shu zi.\n");flag=0;}
else if(flag==1)printf("Your password is wan mei.\n");
}
}
}
*/