Sunday, June 29, 2014

Codeforces Round #163 (Div. 2), problem: (B) Queue at the School solution & swap c++

Codeforces Round #163 (Div. 2), problem: (B) Queue at the School solution & swap <algorithm> c++


Codeforces Round #163 (Div. 2), problem: (B) Queue at the School: http://codeforces.com/problemset/problem/266/B

Codeforces Round #163 (Div. 2), problem: (B) Queue at the School editorial: http://codeforces.com/blog/entry/6499

Codeforces Round #163 (Div. 2), problem: (B) Queue at the School solution: http://ideone.com/RWTq1a

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
    int n, t;
    char s[55];
    scanf("%d%d", &n, &t);
    scanf("%s", s);
    for(int i=0; i<t; i++) for(int j=1; j<n; j++) if(s[j-1]=='B' && s[j]=='G') swap(s[j-1], s[j]), j++;
    printf("%s", s);
    return 0;
}

swap <algorithm> c++: 

there are many swap functions in C++, but we need swap function of <algorithm>





1 comment: