搜索吗。没有头绪哎。SOS!这到底怎么做呀,搜素?凑字数环节
2条回答 默认 最新
- CSDN专家-天际的海浪 2022-04-17 16:42关注
遍历字符串,看看有多少组连续的b和w,把这个数减一就是结果
你题目的解答代码如下:
#include<iostream> #include<string> using namespace std; int main() { int i,count = 1; string str; getline(cin,str); char c = str[0]; int len = str.size(); for (i = 1; i < len; i++) { if (str[i]!=c) { c = str[i]; count++; } } cout << count-1; return 0; }
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录