PAT 乙级 1081 检查密码 (15 分)

题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805261217153024

经验总结:
注意里面有个测试点是包含空格的,所以要用getline的方式来获取字符串。
记:在用getline时,需要注意前面是否有cin等输入,是否需要getchar一下。

C++代码:

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	string s;
	int n;
	cin>>n;
	getchar(); //注意吸收回车,避免接下来的getline获取到。
	while(n--){
		getline(cin,s); //注意字符串里面可能包含空格,所以用getline,否则有个测试点会错误。
		if(s.size()<6){
			cout<<"Your password is tai duan le."<<endl;
		}else{
			bool flag_num = false,flag_char = false,illegal = false;
			for(string::iterator it=s.begin();it!=s.end();it++){
				if(*it>='A'&&*it<='Z'||*it>='a'&&*it<='z'){
					flag_char = true;
				}else if(*it>='0'&&*it<='9'){
					flag_num = true;
				}else if(*it != '.'){
					illegal = true;
					break;
				}
			}
			if(illegal){
				cout<<"Your password is tai luan le."<<endl;
				continue;
			}
			if(flag_num&&flag_char){
				cout<<"Your password is wan mei."<<endl;
			}else if(!flag_num){
				cout<<"Your password needs shu zi."<<endl;
			}else if(!flag_char){
				cout<<"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、付费专栏及课程。

余额充值