2841. Neverland

单点时限: 5.0 sec

内存限制: 256 MB

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

  1. 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)
  1. 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)]
  1. The third sub-sub-community is compounded also by 2 kids at the same level:
  • 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

  1. Only kids can play (sub-communities are not valid)

  2. Only two kids can play at the same time.

  3. If a community have a nested community, the games of the nested community must start first

  4. The winner of a nested community must play with the first kid left to right.

  5. A kid can use the same weapon for main and secondary choices

  6. The kids will always use the same main weapon for all their games. (Exceptions will be described in rule 7).

  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

输入格式

see above~ One case per line.

输出格式

see above~ Each case is separated by a blank line.

样例

Input
[[(Michael-P-S)(John-P-R)[(Peter-P-R)(Campanita-S-P)]](Wendy-S-S)(Guillermo-R-R)]
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)

8 人解决,13 人已尝试。

11 份提交通过,共有 28 份提交。

6.6 EMB 奖励。

创建: 13 年,9 月前.

修改: 6 年,10 月前.

最后提交: 3 年,7 月前.

来源: Mexico 2010

题目标签