赞
踩
题目链接:密码强度等级_牛客题霸_牛客网
注意点:
这道题的坑比较多
1.大小写字符都包含的情况:lowletter && upletter,只要字母存在lowletter || upletter
2.判断小写:islower,判断大写isupper(); 判断数字isdigit();
3.奖励机制问题,注意题干要求只能选择一种以大优先,所以if的判断顺序只能从大到小
- #include<iostream>
- #include<string>
- using namespace std;
-
- int main(){
- string s;
- while(getline(cin, s)){
- int digit = 0;
- int upletter = 0;
- int lowletter = 0;
- int other = 0;
- int sum = 0;
- //密码长度
- int len = s.size();
- if(len <= 4) sum +=5;
- else if(len >= 5 && len <=7 ) sum+=10;
- else if(len >= 8) sum+=25;
- //统计字母,数字,符号个数
- for(int i = 0 ; i < s.size(); ++i){
- //小写字母
- if(islower(s[i])) lowletter++;
- //大写字母
- else if(isupper(s[i])) upletter++;
- //数字
- else if(isdigit(s[i])) digit++;
- //符号
- else other++;
- }
- //全是小(大)写字母,大小写混合字母
- if((lowletter > 0 && upletter == 0) || (upletter > 0 && lowletter == 0)){
- sum += 10;
- }
- //大小写字母混合
- else if (lowletter > 0 && upletter > 0 ) sum +=20;
- //数字
- if(digit == 1) sum += 10;
- else if(digit > 1) sum += 20;
- //符号
- if(other == 1) sum += 10;
- else if(other > 1) sum+= 25;
- //奖励
- //大小写字母,数字,符号
- if(lowletter > 0 && upletter > 0 && digit > 0 && other > 0) sum += 5;
- //字母,数字,符号
- else if((lowletter > 0 || upletter > 0) && (digit > 0) && (other > 0)) sum += 3;
- //字母和数字
- else if((lowletter > 0 || upletter > 0) && (digit > 0)) sum += 2;
- //评分
- if(sum >=90) cout<<"VERY_SECURE"<<endl;
- else if(sum >=80) cout<<"SECURE"<<endl;
- else if(sum>=70) cout<<"VERY_STRONG"<<endl;
- else if(sum >=60) cout<<"STRONG"<<endl;
- else if(sum >=50) cout<<"AVERAGE"<<endl;
- else if(sum>=25) cout<<"WEAK"<<endl;
- else cout<<"VERY_WEAK"<<endl;
- }
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。