B Battle Simulation(icpc水题)

B Battle Simulation

A terrible monster is rampaging through
Neo Tokyo 5! The Earth Defense Force
(EDF) has sent a mech unit1 to defeat the
monster. Because there is only a single
mech unit available after previous monster
rampages, the EDF has decided to simu-
late the upcoming battle between the mech
and the monster before launching an as-
sault. The 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 counter move 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 counter move called Combo breaker, denoted by the letter ‘C’. A single Combo breaker absorbs the entire combination of 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, the 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. The 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
A single line containing a string of at least 1 and at most 1 000 000 characters, consisting of the letters ‘R’, ‘B’ and ‘L’.
1huge bipedal robot, piloted by Japanese teenagers.
Picture by Bandai Namco via Wikimedia Commons 6 Problem B:
Battle Simulation Output
Output a single string consisting 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
RRBBBLLR
Sample Input 2
RBLLLBRR
Sample Input 3
RBLBR
Sample Output 1
SSKKKHHS
Sample Output 2
CHCS
Sample Output 3
CKS

#include<stdio.h>
#include<string.h>
char s[1000005];
char str[1000005];
int main()
{
	int k;
	while(scanf("%s",s)!=EOF)
	{
		int n=strlen(s);
		k=0;
		for(int i=0;i<n;)
		{
			if((s[i]=='R' && s[i+1]=='B' && s[i+2]=='L')
			|| (s[i]=='R' && s[i+1]=='L' && s[i+2]=='B')
			|| (s[i]=='B' && s[i+1]=='R' && s[i+2]=='L')
			|| (s[i]=='B' && s[i+1]=='L' && s[i+2]=='R')
			|| (s[i]=='L' && s[i+1]=='B' && s[i+2]=='R')
			|| (s[i]=='L' && s[i+1]=='R' && s[i+2]=='B'))
			{
				str[k++]='C';
				i+=3;
				if(i==n)
                                  break;
				continue;
			}
			else if(s[i]=='R') str[k++]='S';
			else if(s[i]=='B') str[k++]='K';
			else if(s[i]=='L') str[k++]='H';
			i+=1;
		}
		str[k]='\0';
		printf("%s\n",str);
	}
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值