题解 | #密码强度等级#
密码强度等级
http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
#include <iostream> #include <string> using namespace std; int main() { //input string str; while(cin>>str) { int iLength = 0,iLetter = 0,iNumber = 0,iMark = 0,iAdd=0, iScore=0; bool flaga = 0,flagA = 0; iLength = str.length(); //统计类型 for(int i=0; i<iLength; i++) { //a-z if(str[i]-'a'>=0 && str[i]-'z'<=0) { iLetter++; flaga = true; } //A-Z else if(str[i]-'A'>=0 && str[i]-'Z'<=0) { iLetter++; flagA = true; } //0-9 else if(str[i]-'0'>=0 && str[i]-'9'<=0) { iNumber++; } //other else { iMark++; } } //cout<<iLetter<<" "<<iNumber<<" "<<iMark; if(iLetter) iAdd++; if(iNumber) iAdd++; if(iMark) iAdd++; //长度 iLength = str.length(); if(iLength <= 4) { iScore += 5; } else if(iLength <= 7) { iScore += 10; } else { iScore += 25; } //letter if(iLetter == 0) { iScore += 0; } else if(flagA && flaga) { iScore += 20; } else { iScore += 10; } //数字 if(iNumber==1) { iScore += 10; } else if(iNumber>1) { iScore += 20; } //符号 if(iMark==1) { iScore += 10; } else if(iMark>1) { iScore += 25; } //奖励 if(flagA && flaga && iNumber &&iMark) { iAdd = 5; } else if(iLetter && iNumber &&iMark) { iAdd = 3; } else if(iLetter && iNumber) { iAdd = 2; } iScore += iAdd; if(iScore >= 90) { cout<<"VERY_SECURE"<<endl; } else if(iScore >= 80) { cout<<"SECURE"<<endl; } else if(iScore >= 70) { cout<<"VERY_STRONG"<<endl; } else if(iScore >= 60) { cout<<"STRONG"<<endl; } else if(iScore >= 50) { cout<<"AVERAGE"<<endl; } else if(iScore >= 25) { cout<<"WEAK"<<endl; } else if(iScore >= 0) { cout<<"VERY_WEAK"<<endl; } } //return return 0; }