forked from Vicfred/codeforces-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queueatschool.rs
52 lines (40 loc) · 1.01 KB
/
queueatschool.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// https://codeforces.com/problemset/problem/266/B
use std::io;
fn main() {
let mut line = String::new();
io::stdin()
.read_line(&mut line)
.unwrap();
let words: Vec<i64> =
line
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect();
let n = words[0];
let t = words[1];
let mut s = String::new();
io::stdin()
.read_line(&mut s)
.unwrap();
let mut s: Vec<char> =
s.chars().collect();
let mut time = 0;
while time < t {
let mut idx: usize = 0;
loop {
if idx as i64 >= n+1 {
break;
}
if s[idx] == 'B' && s[idx+1] == 'G' {
s[idx] = 'G';
s[idx+1] = 'B';
idx += 2;
} else {
idx += 1;
}
}
time += 1;
}
let answer: String = s.into_iter().collect();
print!("{}", answer);
}