首页 > 试题广场 >

密码强度等级

[编程题]密码强度等级
  • 热度指数:133874 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
密码按如下规则进行计分,并根据不同的得分为密码进行安全等级划分。

一、密码长度:
5 分: 小于等于4 个字符
10 分: 5 到7 字符
25 分: 大于等于8 个字符

二、字母:
0 分: 没有字母
10 分: 密码里的字母全都是小(大)写字母
20 分: 密码里的字母符合”大小写混合“

三、数字:
0 分: 没有数字
10 分: 1 个数字
20 分: 大于1 个数字

四、符号:
0 分: 没有符号
10 分: 1 个符号
25 分: 大于1 个符号

五、奖励(只能选符合最多的那一种奖励):
2 分: 字母和数字
3 分: 字母、数字和符号
5 分: 大小写字母、数字和符号

最后的评分标准:
>= 90: 非常安全
>= 80: 安全(Secure)
>= 70: 非常强
>= 60: 强(Strong)
>= 50: 一般(Average)
>= 25: 弱(Weak)
>= 0:  非常弱(Very_Weak)

对应输出为:

VERY_SECURE
SECURE
VERY_STRONG
STRONG
AVERAGE
WEAK
VERY_WEAK

请根据输入的密码字符串,进行安全评定。

注:
字母:a-z, A-Z
数字:0-9
符号包含如下: (ASCII码表可以在UltraEdit的菜单view->ASCII Table查看)
!"#$%&'()*+,-./     (ASCII码:0x21~0x2F)
:;<=>?@             (ASCII码:0x3A~0x40)
[\]^_`              (ASCII码:0x5B~0x60)
{|}~                (ASCII码:0x7B~0x7E)

提示:
1 <= 字符串的长度<= 300

输入描述:

输入一个string的密码



输出描述:

输出密码等级

示例1

输入

38$@NoNoN

输出

VERY_SECURE

说明

样例的密码长度大于等于8个字符,得25分;大小写字母都有所以得20分;有两个数字,所以得20分;包含大于1符号,所以得25分;由于该密码包含大小写字母、数字和符号,所以奖励部分得5分,经统计得该密码的密码强度为25+20+20+25+5=95分。
         
示例2

输入

Jl)M:+

输出

AVERAGE

说明

示例2的密码强度为10+20+0+25+0=55分。        
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main() {
    char str[301] = {'\0'};
    while (scanf("%s", str) != EOF) {
        int ret = 0;
        int len = strlen(str);
        int lower = 0;
        int upper = 0;
        int digit = 0;
        int other = 0;
        //1、判断密码长度
        if(len<=4)
        {
            ret += 5;
        }
        else if(len >= 5 && len <= 7)
        {
            ret += 10;
        }
        else
        {
            ret += 25;
        }
        //对密码进行处理记录
        for(int i = 0;i<len ;i++)
        {
            if(isdigit(str[i]))
            {
                if(digit == 0)
                {
                    digit = 1;
                }
                else
                {
                digit = 2;
                }
            }
            else if(islower(str[i]))
            {
                lower = 1;
            }
            else if(isupper(str[i]))
            {
                upper = 1;
            }
            else
            {
                if(other == 0)
                {
                    other = 1;
                }
                else
                {
                    other = 2;
                }
            }
        }
        //数字
        if(digit)
        {
            if(digit == 1)
            {
                ret += 10;
            }
            else
            {
                ret += 20;
            }
            digit = 1;//方便后面奖励加分
        }
        //大小写字母
        if(lower + upper)
        {
            if(lower + upper == 1)
            {
                ret += 10;
            }
            else
            {
                ret += 20;
            }
        }
        //符号
        if(other)
        {
            if(other == 1)
            {
                ret += 10;
            }
            else
            {
                ret += 25;
            }
            other = 1;//方便后面奖励加分
        }
        //奖励
        switch (digit + lower + upper + other)
        {
            case 2 : ret += 2;break;
            case 3 : ret += 3;break;
            case 4 : ret += 5;break;
        }
       
        if(ret >= 90)
        {
            printf("VERY_SECURE\n");
        }
        else if(ret >= 80&& ret <90)
        {
            printf("SECURE\n");
        }
        else if(ret >=70&&ret<80)
        {
            printf("VERY_STRONG\n");
        }
        else if(ret>=60&& ret<70)
        {
            printf("STRONG\n");
        }
        else if(ret>=50&&ret < 60)
        {
            printf("AVERAGE\n");
        }
        else if(ret>=25&&ret <50)
        {
            printf("WEAK\n");
        }
        else
        {
            printf("VERY_WEAK\n");
        }
    }
    return 0;
}
发表于 2023-10-13 23:19:50 回复(0)
#include<stdio.h>
int len=0;
int score=0;
int alp_count[2]={0};
int num_count=0;
int cha_count=0;

void Judge_len(char pwd[]){
if (len <= 4) score += 5;
else if(len > 4 && len <=7) score += 10;
else score += 25;
}

void Judge_alp(char pwd[]){
for(int i=0;i<len;i++){
      if((pwd[i]>='a' && pwd[i]<='z')){
        alp_count[0]=1;
      } 
      if((pwd[i]>='A' && pwd[i]<='Z')) {
        alp_count[1]=1;
      }
    }
    if(alp_count[0]==0 && alp_count[1]==0) score += 0;
    else if(alp_count[0]==1 && alp_count[1]==1) score += 20;
    else score += 10; 
}

void Judge_num(char pwd[]){
    for(int i=0;i<len;i++){
      if((pwd[i]>='0' && pwd[i]<='9')){
         num_count++;
      } 
      if(num_count >= 2) break;
    }
    if(num_count == 0) score += 0;
    else if(num_count == 1) score += 10;
    else score += 20;
}

void Judge_cha(char pwd[]){
   for(int i=0;i<len;i++){
    if(!(pwd[i]>='a' && pwd[i]<='z') &&
       !(pwd[i]>='A' && pwd[i]<='Z') &&
       !(pwd[i]>='0' && pwd[i]<='9')
    ) cha_count ++;
   }
   if(cha_count == 0) score += 0;
    else if(cha_count == 1) score += 10;
    else score += 25;
}

void reward(){
 if((alp_count[0]!=0 && alp_count[1]!=0) && (alp_count[0]!=1 && alp_count[1]!=1) && num_count != 0 && cha_count ==0){
    score += 2;
     }
 if((alp_count[0]!=0 && alp_count[1]!=0) && (alp_count[0]!=1 && alp_count[1]!=1) && num_count != 0 && cha_count !=0){
     score += 3;
     }
 if(alp_count[0]==1 && alp_count[1]==1 && num_count != 0 && cha_count !=0){
      score += 5;
     }
}

void Judge_final(){
  if(score >= 90) printf("VERY_SECURE");
  else if(score >= 80) printf("SECURE");
  else if(score >= 70) printf("VERY_STRONG");
  else if(score >= 60) printf("STRONG");
  else if(score >= 50) printf("AVERAGE");
  else if(score >= 25) printf("WEAK");
  else printf("VERY_WEAK");
}
int main(){
    char pwd[300];
    scanf("%[^\n]",pwd);
    len = (int)strlen(pwd);
    Judge_len(pwd);
    Judge_alp(pwd);
    Judge_num(pwd);
    Judge_cha(pwd);
    reward();
    Judge_final();
    return 0;
}

发表于 2023-05-10 12:42:01 回复(3)
#include <stdio.h>

int main() {
    char password[301];
    gets(password);
    int score=0;
    int numbers=0,symbols=0,letters_small=0,letters_big=0;

    if(strlen(password)<=4)  score+=5;              //密码长度加分
    else if(strlen(password)<=7)  score+=10;
    else score+=25;

    for(int i=0;i<strlen(password);i++){
        if(password[i]>='0'&&password[i]<='9') numbers++;
        else if(password[i]>='a'&&password[i]<='z') letters_small++;
        else if(password[i]>='A'&&password[i]<='Z') letters_big++;
        else symbols++;
    }

    if(letters_big+letters_small==0) ;              //大小写字母加分
    else if(letters_small==0||letters_big==0) score+=10;
    else score+=20;

    if(numbers==0) ;                        //数字个数加分
    else if(numbers==1) score+=10;
    else score+=20;

    if(symbols==0) ;                //符号加分
    else if (symbols==1) score+=10;
    else score+=25;
    
    if(letters_big&&letters_small&&numbers&&symbols)  score+=5;       //奖励
    else if((letters_small+letters_big)&&numbers&&symbols) score+=3;
    else if((letters_small+letters_big)&&numbers)  score+=2;

    //Judgment level
    if(score>=90)
        printf("VERY_SECURE");
    else if(score>=80)
        printf("SECURE");
    else if(score>=70)
        printf("VERY_STRONG");
    else if(score>=60)
        printf("STRONG");
    else if(score>=50)
        printf("AVERAGE");
    else if(score>=25)
        printf("WEAK");
    else
        printf("VERY_WEAK");
    return 0;
}
毫无技巧可言。。。

发表于 2023-03-28 19:51:50 回复(0)
#include <stdio.h>
#include <string.h>
int main() {
    char str[300];
    char* outstr[]={"VERY_SECURE","SECURE","VERY_STRONG","STRONG","AVERAGE","WEAK","VERY_WEAK"};
    scanf("%s", str);
    int score = 0;
    score += strlen(str) <= 4 ? 5 : strlen(str) <= 7 ? 10 : 25;
    int zimuflag = 0, shuziflag = 0, fuhaoflag = 0;
    for (int i = 0; i < strlen(str); i++) {
        if ((zimuflag == 0 || zimuflag == 2) && str[i] >= 'a' && str[i] <= 'z') {
            zimuflag = zimuflag == 2 ? 3 : 1;
        } else if ((zimuflag == 0 || zimuflag == 1) && str[i] >= 'A' && str[i] <= 'Z') {
            zimuflag = (zimuflag == 1) ? 3 : 2;
        } else if (str[i] >= '0' && str[i] <= '9') {
            shuziflag ++;
        } else if ((str[i] >= 0x21 && str[i] <= 0x2F) ||
                   (str[i] >= 0x3A && str[i] <= 0x40) ||
                   (str[i] >= 0x5B && str[i] <= 0x60) ||
                   (str[i] >= 0x7B && str[i] <= 0x7E)) {
            fuhaoflag ++;
        }
    }
    score += (zimuflag == 0 ? 0 : zimuflag < 3 ? 10 : 20);
    score += (shuziflag == 0 ? 0 : shuziflag == 1 ? 10 : 20);
    score += (fuhaoflag == 0 ? 0 : fuhaoflag == 1 ? 10 : 25);
    score += (zimuflag > 0 && zimuflag < 3 && shuziflag > 0 &&fuhaoflag == 0) ? 2 : (zimuflag > 0 && zimuflag < 3 && shuziflag > 0 &&
                                      fuhaoflag > 0) ? 3 : (zimuflag == 3 && shuziflag > 0 && fuhaoflag > 0)?5:0;
//     printf("%d\n", score);
    printf("%s", outstr[6-(score<25?0:score<50?1:score/10-3)]);
}
各种  ?: 赋值语句
发表于 2022-07-11 12:12:13 回复(0)
#include <stdio.h>
#include <string.h>

int lenf(char str[],int len)
{   
if(len<=4)return 5;
else if(len>4&&len<8)return 10;
else if(len>=8)return 25;
}    

int ascf(char str[],int len)
{
    
int dx=0,xx=0,i=0;
    for(i=0;i<len;i++)
    {
        if(str[i]>='a'&&str[i]<='z')
        {  
         xx++;
        }     
        if(str[i]>='A'&&str[i]<='Z')
        {
             dx++;    
        } 
        if(dx==0&&xx==0)return 0;
        else if(xx>0&&dx>0)return 20;
        else if(xx>0||dx>0)return 10;
    }
}    

int numf(char str[],int len)
{
int sz=0,i;
for(i=0;i<len;i++)
{
if('0'<=str[i]&&str[i]<='9')
    sz++;
}    
if(sz==0)return 0;
if(sz==1)return 10;
if(sz>1)return 20;
}    

int fuhaof(char str[],int len)
{
    int fu,i;
    for(i=0;i<len;i++)    
    {
        if(('!'<=str[i]&&'/'>=str[i])||(':'<=str[i]&&'@'>=str[i]))    
        fu++;
        if(fu==0)return 0;    
        else if(fu==1)return 10;
        else if(fu>1)return 25;    
    }
}    

int jlf(char str[],int len)
{
int ascll,num,fuhao=0;
ascll = ascf(str,len);    
num = numf(str,len);
fuhao = fuhaof(str,len);    

if(10<ascll&&0<num&&0<fuhao)return 5;    
else if(0<ascll&&0<num&&0<fuhao)return 3;
else if(0<ascll&&0<num&&0==fuhao)return 2;    
else return 0;
}    

int score(char str[],int len)
{
int zf=lenf(str,len)+ascf(str,len)+numf(str,len)+fuhaof(str,len)+jlf(str,len);    
return zf;
}    



int main()
{
char str[1000];
int len,qd=0;    
gets(str);
len=strlen(str);    
qd=score(str,len);
if(qd>=90)printf("VERY_SECURE");
else if(qd>=80)printf("SECURE");
else if(qd>=70)printf("VERY_STRONG");    
else if(qd>=60)printf("STRONG");
else if(qd>=50)printf("AVERAGE");
else if(qd>=25)printf("WEAK");    
else if(qd>=0)printf("VERY_WEAK");
    
return 0;
}    
发表于 2022-07-01 15:00:23 回复(1)
//毫无技巧,题目怎么说,就怎么写就行
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
    char level[7][15]={ 
        "VERY_SECURE",
        "SECURE",
        "VERY_STRONG",
        "STRONG",
        "AVERAGE",
        "WEAK",
        "VERY_WEAK",
    };
    char password_str[301] = {'\0'};
    int len = 0,letters[2] = {0},nums=0,symbols = 0;
    int i = 0,password_level = 0,score = 0;
    char ch;
    while(scanf("%s",password_str)!=EOF)
    {
        len = strlen(password_str);
        letters[0] = 0;
        letters[1] = 0;
        nums=0;
        symbols = 0;
        for(i = 0; i < len; i++)
        {
            ch = password_str[i];
            if(ch>='a' && ch<='z')
            {
                letters[0]++;
            }
            else if(ch>='A' && ch<='Z')
            {
                letters[1]++;
            }
            else if(ch>='0' && ch<='9')
            {
                nums++;
            }
            else if((ch>=0x21 && ch <=0x2F)|| \
                    (ch>=0x3A && ch <=0x40)||  \
                    (ch>=0x5B && ch <=0x60)||  \
                    (ch>=0x7B && ch <=0x7E))
            {
                symbols++;
            }
        }
        if(len<5)
        {
            score += 5;
        }
        else if(len>=5 && len < 8 )
        {
            score += 10;
        }
        else if(len >= 8)
        {
            score += 25;
        }

        if((letters[0] || letters[1]))
        {
            if(letters[0] && letters[1])
            {
                score+=20;
            } 
            else
            {
                score+=10; 
            }
        }
        if(nums)
        {
            score +=((nums == 1 )?10:20);
        }
        if(symbols)
        {
            score +=((symbols == 1 )?10:25);
        }
        if((nums)&&(letters[0] || letters[1]))
        {
            if(letters[0] && letters[1])
            {
                if(symbols)
                {
                    score += 5;
                }
            }
            else
            {
                if(symbols)
                {
                    score += 3;
                }
                else
                {
                    score += 2;
                }
            }
        }

        if(score < 25)
            printf("%s\n",level[6]);
        else if(score < 50)
            printf("%s\n",level[5]);
        else if(score < 60)
            printf("%s\n",level[4]);
        else if(score < 70)
            printf("%s\n",level[3]);
        else if(score < 80)
            printf("%s\n",level[2]);
        else if(score < 90)
            printf("%s\n",level[1]); 
        else
            printf("%s\n",level[0]); 
    }
    return 0;
}   
发表于 2022-06-19 10:03:36 回复(0)
#include <stdio.h>
#include <string.h>
#define    N    300
int main()
{
    char str[N];
    int len,flag[4]={0},i,score=0;
    gets(str);
    len=strlen(str);
    for(i=0;i<len;i++)
    {
        if(str[i]>='A'&&str[i]<='Z')
            flag[0]++;
        else if(str[i]>='a'&&str[i]<='z')
            flag[1]++;
        else if(str[i]>='0'&&str[i]<='9')
            flag[2]++;
        else 
            flag[3]++;
    }
    //length
    if(len<=4)
        score+=5;
    else if(len<=7)
        score+=10;
    else
        score+=25;
    // alphabet
    if((flag[0]>0&&flag[1]==0)||(flag[0]==0&&flag[1]>0))
        score+=10;
    else if(flag[0]&&flag[1])
        score+=20;
    //number
    if(flag[2]==1)
        score+=10;
    else if(flag[2]>1)
        score+=20;
    //character
    if(flag[3]==1)
        score+=10;
    else if(flag[3]>1)
        score+=25;
    //encourage
    if((flag[0]>0&&flag[1]==0)||(flag[0]==0&&flag[1]>0)&&flag[2])
        score+=2;
    else if((flag[0]>0&&flag[1]==0)||(flag[0]==0&&flag[1]>0)&&flag[2]&&flag[3])
        score+=3;
    else if(flag[0]&&flag[1]&&flag[2]&&flag[3])
        score+=5;
    //Judgment level
    if(score>=90)
        printf("VERY_SECURE");
    else if(score>=80)
        printf("SECURE");
    else if(score>=70)
        printf("VERY_STRONG");
    else if(score>=60)
        printf("STRONG");
    else if(score>=50)
        printf("AVERAGE");
    else if(score>=25)
        printf("WEAK");
    else
        printf("VERY_WEAK");
    return 0;
}

发表于 2022-04-25 10:54:49 回复(0)

#include<stdio.h>
#include<string.h>
/*
密码按如下规则进行计分,并根据不同的得分为密码进行安全等级划分。
一、密码长度:lens  
5 分: 小于等于4 个字符
10 分: 5 到7 字符
25 分: 大于等于8 个字符
二、字母:chrl chru
0 分: 没有字母
10 分: 密码里的字母全都是小(大)写字母
20 分: 密码里的字母符合”大小写混合“
三、数字:nums
0 分: 没有数字
10 分: 1 个数字
20 分: 大于1 个数字
四、符号: signals
0 分: 没有符号
10 分: 1 个符号
25 分: 大于1 个符号
五、奖励(只能选符合最多的那一种奖励):rewards_scores
2 分: 字母和数字
3 分: 字母、数字和符号
5 分: 大小写字母、数字和符号
最后的评分标准:  scores
>= 90: 非常安全
>= 80: 安全(Secure)
>= 70: 非常强
>= 60: 强(Strong)
>= 50: 一般(Average)
>= 25: 弱(Weak)
>= 0:  非常弱(Very_Weak)

对应输出为:

VERY_SECURE
SECURE
VERY_STRONG
STRONG
AVERAGE
WEAK
VERY_WEAK

请根据输入的密码字符串,进行安全评定。
*/
int lens_scores(int lens) {
    int score = 0;
    if (lens <= 4) {
        score = 5;
    } else if (5 <= lens && lens <= 7) {
        score = 10;
    } else {
        score = 25;
    }


    return score;
}
int char_scores(int chrl, int chru) {
    int score = 0;
    if (chrl == 0 && chru == 0) {
        score = 0;
    } else if ((chrl != 0 && chru == 0) || (chrl == 0 && chru != 0)) {
        score = 10;
    } else if ((chrl != 0 ) && (chru != 0) ){
        score = 20;
    }
    return score;
}
int nums_scores(int nums) {

    int score = 0;
    if (nums == 0) {
        score = 0;
    } else if (nums == 1) {
        score = 10;
    } else {
        score = 20;
    }
    return score;
}
int signals_scores(int signals) {
    int score = 0;
    if (signals == 0) {
        score = 0;
    } else if (signals == 1) {
        score = 10;
    } else {
        score = 25;
    }
    return score;

}
int rewards_scores(int chrl, int chru, int nums, int siganls) {
    int score = 0;
    if ((siganls != 0) && (nums != 0) && (chrl != 0 )&& (chru != 0) ) {
        score = 5;
    } else if (((siganls != 0 ) && (nums != 0) && (chrl != 0)) || ((siganls != 0) &&
               (nums != 0) && (chru != 0))) {
        score = 3;
    } else if (((nums != 0) && (chrl != 0)) || ((nums != 0) && (chru != 0))) {
        score = 2;
    } else {
        score = 0;
    }

    return score;
}


int main() {
    int lens = 0, chrl = 0, chru = 0, nums = 0, signals = 0, scores = 0;
    char str[301] = {0};
    while (scanf("%s", &str) != EOF) {
        int lens = strlen(str);
        for (int  i = 0; i < lens; i++) {
            if ('a' <= str[i] && str[i] <= 'z') { //小写字母
                chrl++;
            } else if ('A' <= str[i] && str[i] <= 'Z') { //大写字母
                chru++;
            } else if ('0' <= str[i] && str[i] <= '9') { //数字
                nums++;
            } else {  //其他字符
                signals++;
            }

        }
        scores =  lens_scores(lens) + char_scores(chrl,chru) + nums_scores(nums) + signals_scores(signals) + rewards_scores(chrl, chru,nums, signals);
        if (scores >= 90) {
            printf("VERY_SECURE");
        } else if (scores >= 80 && scores < 90) {
            printf("SECURE");
        } else if (scores >= 70 && scores < 80) {
            printf("VERY_STRONG");
        } else if (scores >= 60 && scores < 70) {
            printf("STRONG");
        } else if (scores >= 50 && scores < 60) {
            printf("AVERAGE");
        } else if (scores >= 25 && scores < 50) {
            printf("WEAK");
        } else {
            printf("VERY_WEAK");
        }





    }

    return 0;
}

发表于 2022-04-04 18:40:05 回复(1)
/*
思路:分别记录密码长度,小写个数,大写个数,数字个数,其他字符个数
      将其传入函数计算得分,再根据得分打印相应字符串
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int calscore(int n, int lac, int uac, int dic, int chc){
    int score = 0;
    
    score += (n>=8)? 25 : ((n>=5)? 10 : 5 );
    score += (lac && uac)? 20 : ((lac || uac)? 10 : 0 );
    score += (dic>1)? 20 : ((dic)? 10 : 0 );
    score += (chc>1)? 25 : ((chc)? 10 : 0 );
    
    score += (lac && uac && dic && chc)? 5 : 
             ((lac|| uac) && dic && chc)? 3 : 
             ((lac|| uac) && dic)? 2 : 0;
    
    return score;
}

void pnt(int score)
{
    if(score >= 90){
        printf("VERY_SECURE\n");
    }else if(score >= 80){
        printf("SECURE\n");
    }else if(score >= 70){
        printf("VERY_STRONG\n");
    }else if(score >= 60){
        printf("STRONG\n");
    }else if(score >= 50){
        printf("AVERAGE\n");
    }else if(score >= 25){
        printf("WEAK\n");
    }else{
        printf("VERY_WEAK\n");
    }
}

int main(void)
{
    char in[300];
    while(scanf("%[^\n]", in) != EOF){
        getchar();
        
        int n, lac, uac, dic, chc;
        n = strlen(in);
        lac = uac = dic = chc = 0;
        for(int i=0; i<n; i++){
            if(isupper(in[i])){
                lac++;
            }else if(islower(in[i])){
                uac++;
            }else if(isdigit(in[i])){
                dic++;
            }else if(isprint(in[i])){
                chc++;
            }
        }
        
        pnt(calscore(n, lac, uac, dic, chc));
    }
    return 0;
}

发表于 2022-02-01 10:05:10 回复(0)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int length_just(char str[],int length)
{
    if(length <= 4) return 5;
    else if(4 < length && length <= 7) return 10;
    else if(length >= 8) return 25;
    return 0;
}

int zimu_just(char str[],int length)
{
    int big = 0,small = 0;
    for(int i = 0; i < length; i++)
    {
        if(str[i] >= 'a' && str[i] <= 'z') small = 1;
        else if(str[i] >= 'A' && str[i] <= 'Z') big = 1;
    }
    if(big == 0 && small == 0) return 0;
    else if(big == 1 && small == 1) return 20;
    else return 10;
    return 0;
}

int number_just(char str[],int length)
{
    int ncnt = 0;
    for(int i = 0; i < length; i++)
    {
        if(str[i] >= '0' && str[i] <= '9') ncnt++;
        
    }
    if(ncnt == 0 ) return 0;
    else if(ncnt == 1) return 10;
    else return 20;
    return 0;
}

int sign_just(char str[],int length)
{
    int scnt = 0;
    for(int i = 0; i < length; i++)
    {
        if((str[i] >= 0x21 && str[i] <= 0x2F) || (str[i] >= 0x3A && str[i] <= 0x40) || (str[i] >= 0x5B && str[i] <= 0x60) || (str[i] >= 0x7B && str[i] <= 0x7E))
        {
            scnt++;
        }
        
    }
    if(scnt == 0 ) return 0;
    else if(scnt == 1) return 10;
    else return 25;
    return 0;
}

int class_just(int v1, int v2, int v3)
{
    if(v1 != 0 && v2 != 0 && v3 == 0) return 2;
    else if(v1 != 0 && v1 != 20&& v2 != 0 && v3 != 0) return 3;
    else if(v1 == 20 && v2 != 0 && v3 != 0) return 5;
    return 0;
}


int main()
{
    char buff = 0;
    int len = 0;
    char strinput[1000];
    
    while(scanf("%c",&buff) != EOF)
    {
        if(buff != '\n')
        {
            strinput[len++] = buff;
        }
        else
        {
            int val1 = length_just(strinput, len);
            int val2 = zimu_just(strinput, len);
            int val3 = number_just(strinput, len);
            int val4 = sign_just(strinput, len);
            int val5 = class_just(val2,val3,val4);
            int val = val1 + val2 + val3 + val4 + val5;
            if(0 <= val && val < 25) printf("VERY_WEAK\n");
            else if(25 <= val && val < 50 ) printf("WEAK\n");
            else if(50 <= val && val < 60 ) printf("AVERAGE\n");
            else if(60 <= val && val < 70 ) printf("STRONG\n");
            else if(70 <= val && val < 80 ) printf("VERY_STRONG\n");
            else if(80 <= val && val < 90 ) printf("SECURE\n");
            else printf("VERY_SECURE\n");
            len = 0;
        }
    }
    return 0;
    
}

发表于 2021-09-03 15:09:22 回复(0)
这应该是最简单的一道题了吧,加一些标志变量最后判断一下即可
#include<stdio.h>
int main(){
    char in[1024];
    while(gets(in)){
        int hasXZM=0; // 小字母
        int hasDZM=0; // 大字母
        int numSZ=0; // 数字个数
        int numFH=0; // 符号个数
        int allDXX=0; // 全大或小写
        int total=0; //总分
        int len=strlen(in);
        //判断长度
        if(len<=4){
            total+=5;
        }else if(len>=5&&len<=7){
            total+=10;
        }else if(len>=8){
            total+=25;
        }

        for(int i=0;i<len;i++){
            if(in[i]>='a' &&  in[i] <='z'){
                hasXZM=1;
            }else if(in[i]>='A' &&  in[i] <='Z'){
                hasDZM=1;
            }else if(in[i]>='0' &&  in[i] <='9'){
                numSZ++;
            }else if((in[i]>='!' && in[i] <='/') || (in[i]>=':' && in[i] <='@') ||
                     (in[i]>='[' && in[i] <='`') || (in[i]>='{' && in[i] <='~')){
                numFH++;
            }
        }
        //统计大小写情况
        if((hasXZM==1&&hasDZM!=1)||(hasXZM!=1&&hasDZM==1)){
            total+=10;
            allDXX=1;
        }else if(hasXZM==1&&hasDZM==1){
            total+=20;
        }
        //统计数字
        if(numSZ==1){
            total+=10;
        }else if(numSZ>1){
            total+=20;
        }
        //统计字母
        if(numFH==1){
            total+=10;
        }else if(numFH>1){
            total+=25;
        }
        //统计奖励
        if((hasXZM==1||hasDZM==1)&&numSZ>=1&&numFH==0){
            total+=2;
        }else if(allDXX==1&&numSZ>=1&&numFH>=1){
            total+=3;
        }else if(allDXX==0&&numSZ>=1&&numFH>=1){
            total+=5;
        }

        if(total>=90){
            printf("VERY_SECURE\n");
        }else if(total>=80){
            printf("SECURE\n");
        }else if(total>=70){
            printf("VERY_STRONG\n");
        }else if(total>=60){
            printf("STRONG\n");
        }else if(total>=50){
            printf("AVERAGE\n");
        }else if(total>=25){
            printf("WEAK\n");
        }else {
            printf("VERY_WEAK\n");
        }
    }
}
发表于 2021-08-06 22:18:39 回复(0)