Neverland
Neverland is compounded by many communities of lost kids. These communities can have one or more kids and/or a nested community (only 1) and that nested community can have one or more kids and/or a nested community (only 1), etc.
Peter Pan decided to celebrate a national championship of “Rock-paper-scissors”. Due the nation is really big he implemented a Web application to set the information. (Only to get the information) from all the kids.
The form requests the following information:
• Name of the kid
• Main weapon (Rock, paper or scissors)
• Secondary weapon (Rock, paper or scissors)∗
The Web application wills export all the information in a String with the following syntax:
[(Name-Main Weapon-Secondary Weapon)(Name-Main Weapon-Secondary Weapon)] Example [(Michael-P-S)(John-P-R)[(Peter-P-R)(Campanita-S-P)](Guillermo-R-R)] Where
() = A kid
[] = Community with two of more kids and also can contain a nested community (Only one is
valid)
S = Scissors P = Paper R = Rock
Example Explanation
- Neverland is integrated by 2 kids, and a sub-community at the same level:
a. [(Michael-P-S)(John-P-R)[(Peter-P-R)(Campanita-S-P)]] b. (Wendy-S-S)
c. (Guillermo-R-R)
- The sub-community is compounded also by 2 kids and a sub-community at the same level:
a. (Michael-P-S) b. (John-P-R)
c. [(Peter-P-R)(Campanita-S-P)]
- The third sub-sub-community is compounded also by 2 kids at the same level:
2/2 a. (Peter-P-R)
b. (Campanita-S-P)
Requirement
Develop a program that get the String generated by the Web Application and process the games (see rules) to provide a general Champion of Neverland.
Game Rules
- Only kids can play (sub-communities are not valid)
- Only two kids can play at the same time.
- If a community have a nested community, the games of the nested community must start first
- The winner of a nested community must play with the first kid left to right.
- A kid can use the same weapon for main and secondary choices
- The kids will always use the same main weapon for all their games. (Exceptions will be described in rule 7).
- If both players (P1, P2) have the same weapon, to avoid a draw they need to use secondary weapons in the following order:
a. P1W1 — P2W1 b. P1W2 — P2W1 c. P1W1 — P2W2 d. P1W2 — P2W2
∗If all options were used and there is not a winner, P1 will be the winner Input
One case per line.
Output
Each case is separated by a blank line.
Sample Input
[(Michael-P-S)(John-P-R)[(Peter-P-R)(Campanita-S-P)](Guillermo-R-R)]
Sample Output
Peter, Weapon: P VS Campanita, Weapon: S
Won: Campanita
Campanita, Weapon: S VS Michael, Weapon: P
Won: Campanita
Campanita, Weapon: S VS John, Weapon: P
Won: Campanita
Campanita, Weapon: P VS Wendy, Weapon: S
Won: Wendy
Wendy, Weapon: S VS Guillermo, Weapon: R
Won: Guillermo
Final Winner: (Guillermo-R-R)