B Battle SimulationPicture by Bandai Namco
via Wikimedia CommonsA terrible monster is rampaging throughNeo Tokyo 5! The Earth Defense Force(EDF) has sent a mech unit1to defeat themonster. Because there is only a singlemech unit available after previous monsterrampages, the EDF has decided to simulatethe upcoming battle between the mechand the monster before launching an assault.The EDF noted that the monster’sattack pattern can be simulated by a series of moves that it performs in succession. Whendenoting each of its moves with a single letter, the attack pattern can be simulated as a singlestring, 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 counter move per move that themonster 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 thethree moves Rake, Bite and Laser breath, in any order, it becomes a very powerful attackfor which the mech must perform a single counter move called Combo breaker, denoted bythe letter ‘C’. A single Combo breaker absorbs the entire combination of three moves. Anyfollowing moves from the monster will have to be countered separately or as part of a newcombination. A move of the monster can never be part of more than one combination.Through extensive analysis of the monster’s past behaviour, the EDF is now able to reliablypredict the actions of the monster ahead of time. You are given a string representing themoves that the monster will use when battling the mech. The EDF needs you to write aprogram that outputs the sequence of moves that the mech must perform in order to defeatthe monster.InputA single line containing a string of at least 1 and at most 1 000 000 characters, consisting ofthe letters ‘R’, ‘B’ and ‘L’.1huge bipedal robot, piloted by Japanese teenagers.6 Problem B: Battle SimulationOutputOutput a single string consisting of the letters denoting the moves that are to be made insuccession by the mech in order to defeat the monster.
Sample Input 1 RRBBBLLR
Sample Output 1 SSKKKHHS
Sample Input 2 RBLLLBRR
Sample Output 2 CHCS
Sample Input 3RBLBR
Sample Output 3 CKS
#include <iostream>
#include <cstring>
#include <cmath>
#include <stack>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <stdlib.h>
using namespace std;
#define INF 9999999
#define MAX 10000
int main()
{
char a[1000008];
cin >> a;
int len = strlen(a);
for(int i = 0; i < len; i++)
{
if(i <= len - 3 && len >= 3)
{
bool f1 = 0, f2 = 0, f3 = 0;
for(int j = i; j < i + 3; j++)
{
if(a[j] == 'L')
f1 = 1;
else if(a[j] == 'B')
f2 = 1;
else if(a[j] == 'R')
f3 = 1;
}
if(f1 && f2 && f3)
{
cout << 'C';
i += 2;
continue;
}
}
if(a[i] == 'L')
cout << "H";
else if(a[i] == 'B')
cout << "K";
else if(a[i] == 'R')
cout << "S";
}
cout << endl;
return 0;
}