我是靠谱客的博主 自信金针菇,这篇文章主要介绍codeforces 266A(Stones on the Table) Java,现在分享给大家,希望可以做个参考。

模拟水题,水得不行。

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* 题意:一排带有颜色的石头,至少拿掉多少个石头,才能使得相邻的石头颜色不一样
*/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(
System.in)));
PrintWriter out = new PrintWriter(System.out);
int stonesNum;
// 石头的数量
int minimunNum;
// 应该拿走石头的最小数量
String stoneColors; // 每个石头的颜色
while (in.hasNext()) {
stoneColors = null;
minimunNum = 0;
stonesNum = in.nextInt();
stoneColors = in.next();
char temp = stoneColors.charAt(0);
for (int index = 1; index < stoneColors.length(); index++) {
if (temp == stoneColors.charAt(index)) {
minimunNum++;
}else{
temp = stoneColors.charAt(index);
}
}
out.println(minimunNum);
}
out.flush();
}
}

最后

以上就是自信金针菇最近收集整理的关于codeforces 266A(Stones on the Table) Java的全部内容,更多相关codeforces内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部