Statistics

Problem Statement for "Handles"

Problem Statement

PROBLEM STATEMENT

In my Division 1 easy problem for SRM 98 I invented a TopCoder member with
handle amhcxa. TopCoder members participate in many of my problems, but in this
problem the handle "amhcxa" had to be a part of the input String[].
Unfortunately, it didn't occur to me at the time I submitted this problem that
the competitors would have to type "amhcxa" many times for their test cases and
would get frustrated as this handle is not typing-friendly. To avoid
frustrating TopCoder members in the future I invented a difficulty rating for
my future fake handles.

The rating works as follows:
1. Start with the number of characters in the handle
2. For each occurrence of the letters 'x','X','z','Z','q', or 'Q', add 2
3. For each maximal set of consecutive consonants add the length of this set
minus 1 (see examples)
4. For each capital letter except the first capital letter, add 1
5. For each digit greater than 1, add 1
6. For each digit '0' or '1' and for each lower-case letter 'l' or upper-case
letter 'O', add 10
7. If the digit '0' and the capital letter 'O' are both present in the handle,
add 100
8. If the digit '1' and the lower-case letter 'l' are both present in the
handle, add 100
9. For each 'h' or 'H' that is followed by a consonant, add 3
10. For each character other than letters or digits add 2
11. For each letter 'q' or 'Q' not followed by a letter 'u' or 'U' add 2.

Your task is, given a String representing a handle, return its difficulty rating.

In more detail:
- the list of consonants in lower-case: bcdfghjklmnpqrstvwxyz
- and the list of consonants in upper-case: BCDFGHJKLMNPQRSTVWXYZ
- consider each of the above rating rules separately

DEFINITION
Class: Handles
Method: difficulty
Parameters: String
Returns: int
Method signature (be sure your method is public): int difficulty(String handle);
 
TopCoder will ensure the validity of the inputs. Inputs are valid if all of the
following criteria are met: 
- handle will have between 1 and 15 characters inclusive
- each character of handle will be one of: a letter [A-Z], [a-z], a digit or
one of the characters: _()=[],./-';+|!~@#$%&*^<>?:

EXAMPLES
1. handle = "amhcxa", start with 6 for the length of the handle, add 2 for 'x',
add 3 for four consecutive consonants, add 3 for a consonant after 'h', return
14. Note that the substring "mhcx" counts as a single set of 4 consecutive
consonants, and not as two sets of 3 or three sets of 2.

2. handle = "C8H10N4O2" - this is the formula for caffeine. We can parse it as
C-eight-H-ten-N-four-O-two. Start with 9 for the length of the handle, add 3
for the extra capital letters, add 3 for the digits '2', '4' and '8', add 10
for the digit '1', add 10 for the digit '0', add 10 for the letter 'O', add 100
for the digit '0' and the letter 'O' both being present, return 145

3. handle = "KleinBottle123", 14 for the length, 1+1+2 = 4 for three sets of
consecutive consonants (note that they are all counted, not just the longest),
1 for the extra capital letter, 2 for the digits '2' and '3', 20 for two
letters 'l', 10 for the digit '1', 100 for the letter '1' and the digit '1'
used together, return 151

4. handle = "gotCHA!", 7 for the length, 2 for non-letter-non-digit characters,
2 for the consonant set, 2 for extra capital letters, return 13

5. handle = "1ll1lll1llll", (one-ell-ell-one-ell-ell-ell-one-ell-ell-ell-ell),
return 238

6. handle = "11111lllll11", (one-one-one-one-one-ell-ell-ell-ell-ell-one-one),
return 236

7. handle = "Queue", returns 7

Definition

Class:
Handles
Method:
difficulty
Parameters:
String
Returns:
int
Method signature:
int difficulty(String param0)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: