TopcoderArchive
Archive
Algorithm problem

EllysPassword

Problem statement, definition, constraints, and public examples.

Problem Statement

The users of the website where Elly has her e-mail account are forced to follow really strict rules for the passwords they choose. Each password must consist of letters of the English alphabet, digits and special symbols only. It must be at least five characters long, and contain at least one capital and one lowercase letter, at least one digit, and at least one special character. The allowed special characters are: {'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '+', '='}.

For research purposes you are trying to break into her e-mail. You've acquired a set of strings written on a piece of paper she accidentally dropped. You believe one of them might be her password. Some of the strings written on the paper don't follow the requirements of the website and can be directly dismissed. You want to write a validation program, which checks whether a string follows the rules of the website.

Your method will be given the String candidate. Return "YES" if it is a potential password and "NO" otherwise.

Definition

Class:
EllysPassword
Method:
validate
Parameters:
String
Returns:
String
Method signature:
String validate(String candidate)
(be sure your method is public)

Constraints

  • candidate will contain between 1 and 20 characters, inclusive.
  • Each character of candidate will be a capital letter ('A'-'Z'), a lowecase letter ('a'-'z'), a digit ('0'-'9'), or one of the following symbols: {'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '+', '='}.

Examples

  1. "P@s5w0rd"
    Returns: "YES"
    "P@s5w0rd" is an allowed password, as it is long enough (its length is 8), it contains an uppercase letter ('P'), a lowercase letter ('s', 'w', 'r', and 'd'), a digit ('5' and '0') and a special character ('@').
  2. "ABab!@#$%^&*()-_+="
    Returns: "NO"
    "ABab!@#$%^&*()-_+=" is not an allowed password, because it does not contain a digit.
  3. "t0pc()d3r"
    Returns: "NO"
    "t0pc()d3r" is not an allowed password, because it does not contain an uppercase letter.
  4. "T0pC()d3r"
    Returns: "YES"
    "T0pC()d3r" is an allowed password.
Back to all problems