文章目录

  • 一、Stones on the Table
  • 总结

一、Stones on the Table

本题链接:Stones on the Table

题目

A. Stones on the Table
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.

Input
The first line contains integer n (1 ≤ n ≤ 50) — the number of stones on the table.

The next line contains string s, which represents the colors of the stones. We’ll consider the stones in the row numbered from 1 to n from left to right. Then the i-th character s equals “R”, if the i-th stone is red, “G”, if it’s green and “B”, if it’s blue.

Output
Print a single integer — the answer to the problem.

Examples

input
3
RRG

output
1

input
5
RRRRR

output
4

input
4
BRBG

output
0

本博客给出本题截图

题意:判断有多少个相邻的相同的色块。

AC代码

#include <iostream>using namespace std;const int N = 60;char s[N];
int res; int main()
{int n;cin >> n;for (int i = 0; i < n; i ++ ) cin >> s[i];for (int i = 0; i < n - 1; i ++ )if (s[i] == s[i + 1]) res ++;cout << res << endl;return 0;
}

总结

水题,不解释

Stones on the Table相关推荐

  1. LeetCode实战:Nim 游戏

    背景 为什么你要加入一个技术团队? 如何加入 LSGO 软件技术团队? 我是如何组织"算法刻意练习活动"的? 为什么要求团队的学生们写技术Blog 题目英文 You are pla ...

  2. leetcode- nim game

    2019独角兽企业重金招聘Python工程师标准>>> You are playing the following Nim Game with your friend: There ...

  3. [leetcode] 数字游戏

    169. Majority Element Given an array of size n, find the majority element. The majority element is t ...

  4. LeetCode 292. Nim Game

    292. Nim Game 尼姆游戏 You are playing the following Nim Game with your friend: 您正在和您的朋友玩以下NIM游戏: There ...

  5. Leet Code OJ 292. Nim Game [Difficulty: Easy]

    题目: You are playing the following Nim Game with your friend: There is a heap of stones on the table, ...

  6. [LeetCode] NO.292 Nim Game

    [题目] You are playing the following Nim Game with your friend: There is a heap of stones on the table ...

  7. 美图笔试算法题(两个人拿石头判断输赢)

    刚做完美图的笔试,两道编程题,第一道比较简单:找出一串用逗号隔开的字符串中不重复的那个数. 以下是第二道,时间有限,很多地方没来得及优化,整体逻辑应该没错. question: You are pla ...

  8. LeetCode之Nim Game

    1.题目 You are playing the following Nim Game with your friend: There is a heap of stones on the table ...

  9. 【ZOJ - 3591】Nim(博弈问题,思维,STLmap)

    题干: Nim is a mathematical game of strategy in which two players take turns removing objects from dis ...

最新文章

  1. php批量导出pdf文件大小,php完美导出pdf,pdf合并批量导出
  2. Lua学习笔记6:C++和Lua的相互调用
  3. window opengl
  4. 网络协议之:一定要大写的SOCKS
  5. 凯撒密码c语言小写字母,凯撒密码c(c语言编程凯撒密码)
  6. React开发(258):react项目理解 ant design debug
  7. omnigraffle 画曲线_Omnigraffle画线框图的新手操作指南
  8. 办公自动化-发送邮件功能-无格式-有格式-带附件-0225
  9. 用Openswan组建Linux IPSec ---第二部分
  10. Linux lsof命令使用小结
  11. 《嵌入式Linux软硬件开发详解——基于S5PV210处理器》——1.2 S5PV210处理器
  12. ESP32 LVGL8.1 ——Label 标签 (Style 14)
  13. 常用Fragstats景观指数
  14. Unity-世界坐标与屏幕坐标
  15. 正则表达式中的前瞻,后顾,负前瞻,负后顾
  16. java curator_使用curator实现选举
  17. netstat -ano|findstr
  18. lzo的正确c语言代码,LZO 使用跟介绍
  19. easyui ajax方式与后台servlet交互原理
  20. 鸿蒙系统乐视手机,首款骁龙870平板官宣;鸿蒙os支持第三方手机;乐视手机高调复活...

热门文章

  1. socket和threading的智能问答机器人服务器与客户端(python)
  2. vCenter Server安装报错:内存或cpu不足
  3. 计算机考研英语复试自我介绍范文,考研英语复试自我介绍范文10篇
  4. socket通信项目开源c语言,优秀的国产高性能TCP/UDP/HTTP开源网络通信框架——HP-Socket...
  5. 1054:三角形判断
  6. centos6系统语言英文改为中文
  7. win10+940mx+pytorch安装的坑
  8. 什么是期权市场的PCR指标?
  9. c语言怎样统计数组的长度,C语言指针难吗?纸老虎而已,纯干货讲解
  10. 【JavaScript】js中的原型继承