Thursday, June 2, 2016

CODEFORCES problem 266B Queue at the School

Problem link (Click here)

#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main()
{
    string s;
    int n, t;
    cin >> n >> t >> s;
    int k,i,j;
    while(t--){
        for(i=0; i<s.length()-1; i++){
            j=i+1;
            if(s[i]=='B' && s[j]=='G'){
                s[i]='G';
                s[j]='B';
                i=j;
            }
        }
    }
    cout << s << endl;

    return 0;

}

No comments:

Post a Comment