Advertisement

上海计算机学会2023年9月月赛C++丙组T1口令的分类

阅读量:
题目描述

给定一串字符序列,请检查它是否符合成为口令的条件,并判断它的强弱。一个合规的口令,需要满足以下两个必要条件:

  • 长度至少为 88,至多为 1616。
  • 只包含以下类型的字符
    1. 大写字母。
    2. 小写字母。
    3. 数字。
    4. 标点符号。符合要求的标点符号如下:
      # & ' ^ " _ = ~ ? ! , . ; : + - * % / | \ ( ) [ ] { } < >

如果一个字符序列包含上述四种字符中的至少三种,则称之为强口令,否则称之为弱口令

输入格式

若干个字符,表示一个有待验证的字符串,保证每个字符都是可见字符,保证不会出现空格或换行。

输出格式
  • 如果输入的密码串不合规,输出 Invalid password
  • 合规但密码较弱,输出 Weak password
  • 否则,输出 Strong password
样例数据

输入:

123456!Aa

输出:

Strong password

题解

本题关键点:判断遇到非法的特殊字符的处理。代码如下。

复制代码
 #include <iostream>

    
 #include <string>
    
 using namespace std;
    
 int main(){
    
 	string s,marks;
    
 	cin>>s;
    
 	marks="#&'^\"_=~?!,.;:+-*%/|\ ()[]{}<>";
    
 	int len,sum;
    
 	bool x;
    
 	sum=0;
    
 	x=true;
    
 	int ans[4]={0,0,0,0};
    
 	len=s.length(); 
    
 	if(len>=8 && len<=16){		
    
 		//判定是否是字母,判断是否是数字
    
 		for(int i=0;i<len;i++){
    
 			if(s[i] >= 'A' && s[i] <= 'Z')
    
 				ans[0]=1;
    
 			else if(s[i] >= 'a' && s[i] <= 'z')
    
 				ans[1]=1;
    
 			else if(s[i] >= '0' && s[i] <= '9')
    
 				ans[2]=1;
    
 		    else{
    
 		    	bool y=false;
    
 		    	for(int j=0;j<marks.length();j++){
    
 					if(s[i]==marks[j]){
    
 						ans[3]=1;
    
 						y=true;
    
 						break;
    
 					}
    
 		    	}
    
 				//判断是否遇到非法的特殊字符
    
 				if(!y){
    
 					x=false;
    
 				}		    	
    
 			}
    
 		}
    
 		if(x){
    
 			for(int k=0;k<4;k++){
    
 				if(ans[k]>0){
    
 					sum++;
    
 				} 
    
 			}
    
 			if(sum>=3){
    
 				cout<<"Strong password"<<endl;
    
 			}else{
    
 				cout<<"Weak password"<<endl;
    
 			}	
    
 		}else{
    
 			cout<<"Invalid password"<<endl;
    
 		}		
    
 		
    
 	}else{
    
 		cout<<"Invalid password"<<endl;
    
 	}
    
 	
    
 	return 0;
    
 }
    
    
    
    

全部评论 (0)

还没有任何评论哟~