You and your friends are playing your favorite fighting game at a local LAN-party. After button-mashing for several hours (and getting your behind handed to you) you decide

QuestionsCategory: QuestionsYou and your friends are playing your favorite fighting game at a local LAN-party. After button-mashing for several hours (and getting your behind handed to you) you decide
Pete asked 5 months ago

You and your friends are playing your favorite fighting game at a local LAN-party. After button-mashing for several hours (and getting your behind handed to you) you decide that your life is too short to remember intricate combos and counter moves, so you decide that it is just another thing you need to automate in your long career of automation.
In this game, your rival will make a sequence of moves, and each move in this sequence must be countered with your own moves. Your rival has 4 different moves (each shortened to letter-form): C, L, R, and S. You can counter each move with the respective counter move M, E, C, and S. The moves can come from your rival in any order, and you have to counter each of them with the corresponding counter move, in the same order as the opponent.
Though, you need to be careful: Any permutation of the sequence ‘C L R S’ from your rival in a row is a special combo, and must be countered by the counter move F (the combobreaker). A rival move can only belong to one combo (with priority to the first one encountered), and all 4 moves in a combo must be countered by the single combobreaker and nothing else. So for instance ‘C R L S C’ must be countered by ‘F M’.
Given the sequence of all your rival’s moves, you must output the list of counter moves you should make.
Input format

  • First line: an integer NN, indicating the number of moves your rival makes (N\leq10^6N≤106).
  • Second line: NN space separated letters, indicating your rival’s moves. The letters will always be one of ‘R’, ‘L’, ‘C’, or ‘S’.

Output format

  • One line containing the letters of your counter moves separated by space. All letters should be one of ‘M’, ‘E’, ‘C’, ‘S’, or ‘F’.

Examples Input 118 2 CLRCSRCL Output 1 MFCME

1 Answers
Techtuna Staff answered 5 months ago

Answer:
Explanation:
First we will take the integer and store all the characters inside the array.
After that, we will traverse the array one by one and if there are 4 elements after the current index, we will check if C, L, R and S , all of them are present in the next four including current one. If it is present, we output F and increase i by 3 index so that these index are not traversed again. If not, we will just output the counter alphabet.
here is the code:

#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
char a[n];

for(int i=0; i<n; i++)
{
cin>>a[i];
}

for(int i=0; i<n; i++)
{
if(i<n-4)
{
bool c, l, r, s;
for(int j=i; j<i+4; j++)
{
if(a[j]==\’C\’)
c = true;
if(a[j]==\’L\’)
l = true;
if(a[j]==\’R\’)
r = true;
if(a[j]==\’S\’)
s = true;

}

if(c && l && r && s)
{
cout<<\”F \”;
i = i+3;
}
else
{
if(a[i]==\’C\’)
cout<<\”M \”;
if(a[i]==\’L\’)
cout<<\”E \”;
if(a[i]==\’R\’)
cout<<\”C \”;
if(a[i]==\’S\’)
cout<<\”S \”;
}
}
else
{
if(a[i]==\’C\’)
cout<<\”M \”;
if(a[i]==\’L\’)
cout<<\”E \”;
if(a[i]==\’R\’)
cout<<\”C \”;
if(a[i]==\’S\’)
cout<<\”S \”;

}
}
return 0;
}

Output: