码蹄杯 排队 题型:模拟

52 阅读1分钟

码题集OJ-排队 (matiji.net)

image.png

样例输入:

5 1
BGGBG

样例输出:

GBGGB

蒙一下蒙对了:

#include<bits/stdc++.h>
using namespace std;
int n,k;
int main()
{
	cin>>n>>k;
	string s;cin>>s;
	
	while(k--)
	{
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='B'&&s[i+1]=='G')
			{
			  swap(s[i],s[i+1]); 
			  i++;
			}
		}
	}
cout<<s;
	return 0;
}

image.png