牛客网链接: link.
思路不难,就是一个C语言的逻辑语句
#include<iostream>
#include<string>
using namespace std;
int score_count(const string& s)
{
int digit = 0,symbol = 0;//数字和特殊符号
int lower = 0,upper = 0,charactor = 0;
int size = 0,sum = 0;
for(auto ch : s)
{
if(ch >= '0' && ch <= '9'){
digit++;
}else if(ch >= 'a' && ch <= 'z'){
lower++;
charactor++;
}else if(ch >= 'A' && ch <= 'Z'){
upper++;
charactor++;
}else if((ch >= 0x21 && ch <= 0x2F) ||
(ch >= 0x3A && ch <= 0x40) ||
(ch >= 0x5B && ch <= 0x60) ||
(ch >= 0x7B && ch <= 0x7E)){
symbol++;
}
}
//数字
if(digit ==1){
sum += 10;
}else if(digit > 1){
sum += 20;
}
//字母
if((lower == charactor) || (upper == charactor)){
sum +=10;
}else if(lower > 0 && upper > 0){
sum += 20;
}
//符号
if(symbol == 1){
sum +=10;
}else if(symbol > 1){
sum += 25;
}
//长度
size = s.size();
if(size <= 4){
sum += 5;
}else if(size <= 7){
sum += 10;
}else{
sum += 25;
}
//奖励
if(digit > 0 && lower > 0 && upper > 0 && symbol>0){
sum += 5;
}else if(digit >0 &&(lower > 0 || upper > 0) && symbol > 0){
sum += 3;
}else if(digit >0 &&(lower > 0 || upper > 0) && symbol == 0){
sum += 2;
}
return sum;
}
int main()
{
string s;
while(cin >> s)
{
int score = score_count(s);
if(score >= 90){
cout<< "VERY_SECURE"<<endl;
}else if(score >= 80){
cout<< "SECURE"<<endl;
}else if(score >= 70){
cout<< "VERY_STRONG"<<endl;
}else if(score >= 60){
cout<< "STRONG"<<endl;
}else if(score >= 50){
cout<< "AVERAGE"<<endl;
}else if(score >= 25){
cout<< "WEAK"<<endl;
}else{
cout<< "VERY_WEAK"<<endl;
}
}
return 0;
}