您的位置:首页 > 科技 > IT业 > HJ87密码等级

HJ87密码等级

2024/12/21 23:12:02 来源:https://blog.csdn.net/2301_77560238/article/details/140699249  浏览:    关键词:HJ87密码等级

这个题目就是细心处理一下就行,比较简单

#include <ctype.h>
#include <stdio.h>
#include <stdbool.h>void PrintLevel(unsigned int score)
{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 if(score >= 0){printf("VERY_WEAK");}
}int GetScoreByStrlen(int *score, unsigned int len)
{if(len <= 4){*score = 5;}else if(len <= 7){*score = 10;}else {*score = 25;}return 0;
}int GetScoreByCharacter(int *score, char* array, int len)
{bool withAlphaFlag = false;bool alphaWithLowerFlag = false;bool alphaWithUpperFlag = false;bool withDigitFlag = false;int digitCount = 0;bool withCharacterFlag = false;int characterCount = 0;for(int i = 0; i < len; i++){if(isalpha(array[i])){withAlphaFlag = true;if(array[i] >= 'a' && array[i] <= 'z'){alphaWithLowerFlag = true;}if(array[i] >= 'A' && array[i] <= 'Z'){alphaWithUpperFlag = true;}}else if(isdigit(array[i])){withDigitFlag = true;digitCount++;}else {withCharacterFlag = true;characterCount++;}}int alphaScore = 0;if(!withAlphaFlag){alphaScore = 0;}else {if(alphaWithLowerFlag && alphaWithUpperFlag){alphaScore = 20;}else {alphaScore = 10;}}*score += alphaScore;int digitScore = 0;if(!withDigitFlag){digitScore = 0;}else {if(digitCount == 1){digitScore = 10;}else {digitScore = 20;}}*score += digitScore;int characterScore = 0;if(!withCharacterFlag){characterScore = 0;}else {if(characterCount == 1){characterScore = 10;}else {characterScore = 25;}}*score += characterScore;int specialScore = 0;if(alphaWithLowerFlag && alphaWithUpperFlag && withDigitFlag && withCharacterFlag){specialScore = 5;}else if(withAlphaFlag && withDigitFlag && withCharacterFlag){specialScore = 3;}else if(withAlphaFlag && withDigitFlag){specialScore = 2;}*score += specialScore;return 0;
}int main() {char strArray[301] = {'\0'};while (scanf("%s",strArray) != EOF) { // 注意 while 处理多个 case// 64 位输出请用 printf("%lld") to int score = 0;int len = strlen(strArray);GetScoreByStrlen(&score, len);GetScoreByCharacter(&score, strArray, len);PrintLevel(score);}return 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com