1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
const char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
lower[] = "abcdefghijklmnopqrstuvwxyz",
number[] = "0123456789",
special[] = "!\"œ$%^&*()_+{}:@~|<>?-=[]'#\\,./ª`";
const char rating[6][13] = { "?", "Unacceptable", "Poor", "Weak", "Good", "Best" };
bool lap( const char* a, const char* b )
{
if ( !*a ) return false;
for ( auto bb = (char*)b; *bb; bb++ ) if ( *a == *bb ) return true;
return lap( a + 1, b );
}
int length( const char* a ) { return *a ? 1 + length( a + 1 ) : 0; }
int PWRating( const char* pw ) { return ( length( pw ) >= 8 ) + lap( pw, upper ) + lap( pw, lower ) + lap( pw, number ) + lap( pw, special ); }
int main()
{
for ( auto pw : {"last","lastchance","lastChance","lastChance9","lastChance9?" } ) std::cout << pw << " " << rating[PWRating(pw)] << '\n';
}
| |