Problem Statement
PROBLEM STATEMENT Your best friend is a TopCoder member and invites you to join TopCoder. As he expects you to win a lot he asks you not to forget to reference his handle (TopCoder has a referral system: when you provide the handle of your referee, your referee will get 10% of your winnings). To make sure you get his handle correctly he sends it to you by fax. After reminding him that your printer is not very good at recognizing text (you have a new printer with some super modern software inside), he decides to send his handle by repeating each character 3 times. Your printer software tries to recognize letters and digits during fax transmission and does its best to place a guess. If the software can't recognize a character, it places a star: '*'. So you may receive something like this: BBBoootttoaommmCCCoo*d*deeerrr. You decide to recover his handle with the following procedure. You parse the received String in triples (that is, you take the first three characters from the input String and decide what to do with them, then you take the next three, and so on). For each triple you take a majority vote. More precisely: - If two or more letters/digits are the same you pick this character in your result. For example, you will recover the following strings as 'a': aaa, aba, aa*. - If you have only one letter/digit in a triple and two stars, you pick that letter/digit. For example, you will recover the following string as 'a': **a. - In all other cases you exchange the triple for '*'. Your task is, given an arbitrary String of letters and digits, to return the original handle following the procedure described above. DEFINITION Class: TripleCode Method: handle Parameters: String Returns: String Method signature (be sure your method is public): String handle(String tripleHandle); TopCoder will ensure the validity of the inputs. Inputs are valid if all of the following criteria are met: - tripleHandle will consist only of letters [A-Z] and [a-z] inclusive, digits [0-9] inclusive, and the star character '*' - tripleHandle will have between 3 and 45 characters inclusive - tripleHandle's length will be divisible by 3. Note: letters are case sensitive. That is: "AaAaAa" would return "Aa". EXAMPLES 1. tripleHandle = "NaNoooTttaaaCCCo*oddde***rr" returns "NotaCoder" 2. tripleHandle = "axaxaxchchchmamama" returns "axchma" 3. tripleHandle = "abcdef" returns "**" 4. tripleHandle = "JJjaAavVvaaA" returns "Java" 5. tripleHandle = "p*a1234a4" returns "**4" 6. tripleHandle = "AaAaAa" returns "Aa" 7. tripleHandle = "Aa*" returns "*"
Definition
- Class:
- TripleCode
- Method:
- handle
- Parameters:
- String
- Returns:
- String
- Method signature:
- String handle(String param0)
- (be sure your method is public)
Constraints
Examples
No public sample cases were explicitly marked for this problem in the original data.