OJ in class: Determine the password strength and oj password strength.

Source: Internet
Author: User

OJ in class: Determine the password strength and oj password strength.

One problem in determining password strength:

Assume that the following four types of characters are allowed as passwords:
(1) uppercase English letters, (2) lowercase English letters, (3) numbers 0-9, (4) special symbols @-_#~
Set the password strength as follows:
Best: The length is greater than or equal to 16 and contains the above four types of characters. Each type has at least two different characters.
Strong: does not comply with the Best rules, but the length is greater than or equal to 10, and contains the above four types of Characters
Medium: does not comply with the Best and Strong rules, but the length is greater than or equal to 8, and contains at least three types of Characters
Weak: does not comply with Best, Strong, and Medium rules.
Here is a password combination. Determine the password strength.
Input Format: a line of string (length <100, ending with a line break), and must be of the above four types of characters.
Output Format: one line of information. The length of the password is output first, followed by the strength level, with a blank space in the middle.

Input Example 1: abcdXYZ1234 @-_-#
Output example Best
Input Example 2: 12345678 abcdefghXYZ
Sample output: Medium
Input Example 3: aX1 @
Output Example 3: 4 Weak

 

The key to the question is that each type of Best has at least two different characters. To implement this function, you can define multiple arrays.

C source code: # include "stdio. h"
Int main ()
{
Char a [100], sz [100], ZM [100], zm [100], fh [100];
Int I, j, k, l, m, n, sum, zm0, ZM0, sz0, fh0;
I = 0;
K = l = m = n = 0;
Zm0 = 0;
ZM0 = 0;
Sz0 = 0;
Fh0 = 0;
Sum = 0;
While (a [I] = getchar ())! = '\ N ')
{
I ++;
}
For (j = 0; j <I; j ++)
{
If (a [j]> = 'A' & A [j] <= 'Z ')
{
ZM [k] = a [j];
K ++;
}

Else if (a [j]> = 'A' & a [j] <= 'Z ')
{
Zm [l] = a [j];
L ++;
}
Else if (a [j]> = '0' & a [j] <= '9 ')
{
Sz [m] = a [j];
M ++;
}
Else
{
Fh [n] = a [j];
N ++;
}
}
Sum = k + l + m + n;
While (k --)
{
ZM0 ++;
If (ZM [k] = ZM [k-1])
ZM0 --;
}
While (l --)
{
Zm0 ++;
If (zm [l] = zm [L-1])
Zm0 --;
}
While (m --)
{
Sz0 ++;
If (sz [m] = sz M-1])
Sz0 --;
}
While (n --)
{
Fh0 ++;
If (fh [n] = fh [n-1])
Fh0 --;
}
If (sum> = 16 & ZM0> = 2 & zm0> = 2 & sz0> = 2 & fh0> = 2)
Printf ("% d Best \ n", sum );
Else if (sum> = 10 & ZM0> = 1 & zm0> = 1 & sz0> = 1 & fh0> = 1)
Printf ("% d Strong \ n", sum );
Else if (sum> = 8 & (ZM0> = 1 & zm0> = 1 & sz0> = 1) | (zm0> = 1 & ZM0> = 1 & fh0> = 1) | (zm0> = 1 & sz0> = 1 & fh0> = 1 )))
Printf ("% d Medium \ n", sum );
Else
Printf ("% d Weak \ n", sum );
Return 0;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.