PROBLEM STATEMENT:
In an attempt to prevent dirty obfuscation tricks, TopCoder decides to outlaw
the use of variable names l (lowercase L) and O (uppercase o). Also, any
variable names consisting of solely l's (lowercase L's) and 1's (ones) and O's
(uppercase o's) and 0's (zeros) and other digits are prohibited. For example,
l111ll1 (L, one, one, one, L, L, one) cannot be used as a variable name. Also,
l03 (L, zero, three) is not allowed. These variables are not allowed because
they can all be misread as numbers.
Another form of obfuscation involves using two variable names that look similar
on screen but are actually different. For example, counterl (last character is
L) and counter1 (last character is "one").
Assume that the only types allowed in a program are "int", "double", and
"char". Also, assume that variable names start with a letter and only contain
letters and digits. Type names are not allowed as variable names (for example,
you can't have a variable named "int").
Given a piece of code as input, return all starting indices (in ascending
order) of variable declarations where the variable name is obfuscated. A
variable name is obfuscated if it looks like a number, or if it looks like
another variable declared elsewhere in the code (as described above). A
variable declaration is defined here as:
<type name><one or more spaces><variable name>(<space> or <';'> or <'='>)
The above should be interpreted as follows: a type name, followed by one or
more spaces, followed by a variable name, followed by either a space, a
semicolon, or an equals sign.
Variable declarations must be preceded by either a space or a semi-colon -
unless the type declaration begins at index 0 of the input string. Note that
this variable declaration scheme would not work in real life because it would
not cover all possible valid variable declarations in a real program.
For example, consider the following input string:
"int x = 0;"
A variable declaration begins at index 0.
Now, consider the following input string:
"int x;int y= 0"
Two variable declarations exist: one starting at index 0, the other starting at
index 6 (where the second "int" begins).
However, in the following case:
"int x = 0int y= 0;
There is only one variable declaration starting at index 0 - the second "int"
is not preceded by a space or semi-colon.
Examples of variable declarations:
"int VariableName;"
"double dd ;"
"int l1l1l = 11110"
"int O=1;"
"char b "
The following do not count as variable declarations:
"intVariableName;"
"double=d=3.0;"
"char X}"
"do uble x=2;"
"Double d;" (types are case sensitive)
"double p" (variable name is not followed by a space, equals sign, or
semi-colon)
The input code will not necessarily contain syntactically correct code. For
example:
"int l=3; int int int ll1;;"
The above code is not syntactically correct, but the method should still return
the starting indices of "int l" and "int ll1". The following is also allowed:
"int l3 = 3;char l3=false "
It should return the starting indices of "int l3" and "char l3"
TopCoder will ensure the following criteria on the inputs:
* code will contain between 0 and 50 characters inclusive.
* code will only contain the following types of characters: letters (a-z, A-Z),
digits (0-9), spaces, or any character contained in the following string:
"=;+-()/*:{}[]" (quotes are for clarity, they are not included in the string).
DEFINITION
Class name: Cheater
Method name: isObfuscated
Parameters: String
Returns: int[]
The method signature is:
public int[] isObfuscated(String code);
Make sure your method is public.
EXAMPLES
(We recommend you copy and paste examples to be sure you input them correctly)
"int l=0; if(x==l) return false;" -> {0}
- because int l (lowercase L) is an obfuscation.
"double l" -> {}
- because there is no valid variable declaration.
"char ll3=true/ int O4;" -> {0,15}
- because char ll3 (lowercase L, lowercase L, 3) is an obfuscation, and int
O4 (uppercase o, 4) is an obfuscation.
"//i cheat; int cheatl =3;int cheat1 = 4 xx(cheatl)" -> {11,25}
- because int cheatl (last character is a lowercase L) and int cheat1 (last
character is the number one) look alike.
"int clll1; int l1; int cl111; l1=3; int c1" -> {0,11,19}
- because int clll1 (c, lowercase L, lowercase L, lowercase L, number one)
and int cl111 (c, lowercase L, number one, number one, number one) look alike,
and int l1 (lowercase L, number one) is an obfuscation.
"// xs ;int xO; int x0; x0 = xO + xO;" -> {7,15}
- because int xO (last character is an uppercase o) and int x0 (last
character is the number zero) look alike.
"" -> {}