秒一波水题,提提神!!!
复制代码
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
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* 题意:n 个孩子排队,每分钟每人只能换一次位置。如果遇到男孩在女孩的前面,则两人换位置。输出 t 分钟之后的位置序列。
*/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int childrenNum; // 孩子数量
int time; // 几分钟之后
char[] queue; // 队伍序列
while (in.hasNext()) {
childrenNum = in.nextInt();
time = in.nextInt();
queue = in.next().toCharArray();
while (time-- != 0) {
for (int index = 1; index < childrenNum; index++) {
if (queue[index - 1] == 'B' && queue[index] == 'G') {
queue[index - 1] = 'G';
queue[index] = 'B';
index++;
}
}
}
for (char ch : queue) {
out.print(ch);
}
out.println();
}
out.flush();
}
}
最后
以上就是快乐小蜜蜂最近收集整理的关于codeforces 266B(Queue at the School) Java的全部内容,更多相关codeforces内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复