赞
踩
这个题目就是细心处理一下就行,比较简单
#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; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。