Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions 266B - Queue at the School.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
//4021768 Jul 4, 2013 7:57:17 PM fuwutu 266B - Queue at the School GNU C++0x Accepted 15 ms 0 KB
#include <iostream>
#include <string>

using namespace std;

int main()
{
int n, t;
string s;
cin >> n >> t >> s;
while (t--)
{
for (int i = 1; i < n; ++i)
{
if (s[i] == 'G' && s[i-1] == 'B')
{
s[i] = 'B';
s[i-1] = 'G';
++i;
string swap_action(string str){
for(int i = 1; i<str.length(); i++){
if(str.at(i-1) == 'B' && str.at(i) == 'G'){
str.at(i) = 'B';
str.at(i-1) = 'G';
i++;
}
}
return str;
}

int main(){

int student, t;
string s;

cin >> student >> t;
cin.ignore();

getline(cin, s);

for(; t > 0; t--){
s = swap_action(s);
}

cout << s << endl;

return 0;
}