Programming contests

DEIK Regionális Programozó Csapatverseny, nyílt kategória, 2017. december 3.

December 3, 2017 10:10 AM – December 3, 2017 3:10 PM

F — Battle Simulation


Picture by Bandai Namco

A terrible monster is rampaging through Neo Tokyo 5! The Earth Defense Force (EDF) has sent a mech unit (a huge bipedal robot, piloted by Japanese teenagers) to defeat the monster. Because there is only a single mech unit available after previous monster rampages, EDF has decided to simulate the upcoming battle between the mech and the monster before launching an assault. EDF noted that the monster's attack pattern can be simulated by a series of moves that it performs in succession. When denoting each of its moves with a single letter, the attack pattern can be simulated as a single string, which should be read from left to right. The monster has the following moves:

  • Rake, denoted by the letter 'R';
  • Bite, denoted by the letter 'B';
  • Laser breath, denoted by the letter 'L'.

In order to defeat the monster, the mech must perform a countermove per move that the monster makes:

  • Slice, denoted by the letter 'S', counters the monster's rake;
  • Kick, denoted by the letter 'K', counters the monster's bite;
  • Shield, denoted by the letter 'H', counters the monster's laser breath;

However, there is one catch. When the monster performs a subsequent combination of the three moves Rake, Bite, and Laser breath, in any order, it becomes a very powerful attack, for which the mech must perform a single countermove called Combo breaker, denoted by the letter 'C'. A single Combo breaker absorbs the entire combination of the three moves. Any following moves from the monster will have to be countered separately or as part of a new combination. A move of the monster can never be part of more than one combination.

Through extensive analysis of the monster's past behaviour, EDF is now able to reliably predict the actions of the monster ahead of time. You are given a string representing the moves that the monster will use when battling the mech. EDF needs you to write a program that outputs the sequence of moves that the mech must perform in order to defeat the monster.

Input Specification

The input consists of a single line with a string of at least 1 and at most 1 000 000 characters, containing the letters 'R', 'B', and 'L'.

Output Specification

Output a single string that consists of the letters denoting the moves that are to be made in succession by the mech in order to defeat the monster.

Sample Input 1

  1. RRBBBLLR
download as text file

Output for Sample Input 1

  1. SSKKKHHS
download as text file

Sample Input 2

  1. RBLLLBRR
download as text file

Output for Sample Input 2

  1. CHCS
download as text file

Sample Input 3

  1. RBLBR
download as text file

Output for Sample Input 3

  1. CKS
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019