【2019暑期】【PAT乙级】1081 检查密码 (15 分)

48 篇文章 0 订阅

注意

isalnum() 是数字或字母返回 非零,不是返回1
其他情况返回0

该题需注意空格问题,不是字符串中有空格,是字符串结尾有空格,所以用getline

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <cctype>
#include <vector>
#include <cmath>
#include <map> 

using namespace std;
	
int main(){
	
	int n;
	cin >> n;
	getchar();
	for(int i=0; i<n; i++){
		string a;
		getline(cin,a);		
		if(a.length() < 6){
			cout << "Your password is tai duan le." << endl;
			continue;
		}
		int num = 0;
		int let = 0;
		int other = 0; 
		for(int j=0; j<a.length(); j++){
			if(isalnum(a[j]) != 0){
				if(isdigit(a[j])) num = 1;
				if(isalpha(a[j])) let = 1;
			}
			else if(a[j] == '.') continue;
				 else {
				 	other = 1;
				 	break;
				 } 
		}
		if(other == 1 || (num ==0 && let == 0))
			 cout << "Your password is tai luan le." << endl;		
		else if(num == 1 && let == 0)
			 cout << "Your password needs zi mu." << endl;
		else if(num == 0 && let == 1)
			 cout << "Your password needs shu zi." << endl;
		else cout << "Your password is wan mei." << endl;
	}
	
	return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值