Java - CodeForces - 266A
2023-03-14 09:43:52 时间
题目:
桌子上有n块石头排成一行,每一块都可以是红色、绿色或蓝色。计算从表中取出的石头的最小数量,以便相邻的任何两块石头具有不同的颜色。如果一排石头之间没有其他石头,则认为它们相邻。
输入:
第一行包括一个正整数 n (1 ≤ n ≤ 50) -桌上石头的数量。
下一行包含字符串s,它表示石头的颜色。我们将考虑从左到右编号为1到n的行中的石头。然后,第i个字符s等于“R”,如果第i个石头是红色的,则等于“G”,如果是绿色的,则等于“B”,如果是蓝色的。
输出:
打印单个整数-问题的答案
样例:
input
3
RRG
output
1
input
5
RRRRR
output
4
input
4
BRBG
output
0
思路
这道题思路很简单,直接看代码就能看懂
代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { int n,i,m=0; Scanner scanner = new Scanner(System.in); n = scanner.nextInt(); char[] c = scanner.next().toCharArray(); for (int j = 0; j < n-1; j++) { if (c[j]==c[j+1]) { m++; } } System.out.println(m); } }
相关文章
- Fiddler win10:Failed to register Fiddler as the system proxy
- nginx: [emerg] host not found in upstream "cdn.xieboke.net" in /usr/local/nginx/conf/vhost/joyo.ink.
- 树莓派 安装 Nextcloud 出现“内部服务器错误”
- 树莓派4B 安装 nextcloud 做私人云盘网盘(nginx + docker + nextCloud + redis)
- async 函数和 promises 的性能提升
- web 服务器 caddy 资料收集
- The unit caddy.service has entered the 'failed' state with result 'exit-code'
- 官方文档:QUX主题使用指南
- centos7 java -verison Error: Could not create the Java Virtual Machine.
- Django admin admin_order_field 自定义字段排序实现方法
- centos7 systemctl 添加 uwsgi(开机启动)
- django import_export 按用户类型显示导入导出按钮
- docker 常用命令
- Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running
- pycharm ModuleNotFoundError: No module named 'settings'
- 启动 fiddler 时取消开启 capturing 的方法(Fiddler no capture on startup)
- monitor.exe 无法启动,启动时报错的解决办法(已安装最新的 jdk)
- windows 安装 virtualenvwrapper-win 和设置 WORKON_HOME 环境变量
- var,let,const三者的特点和区别
- 安卓手机摄像头变成电脑(windows)的摄像头(DroidCam 摄像头)