You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
995 B

#include <bits/stdc++.h>
using namespace std;
int main() {
/*
规律:
当这一个硬币与下一个硬币不同时,这一个硬币连同它之前的硬币一起翻转
翻转至与下一个硬币相同的一面,直到将所有硬币翻转到同一面
但这里还有一个点要注意:题目要求所有硬币正面朝上,也就是所有面都是'1'的情况,才算完成.我们就再把全部硬币翻转一次
*/
//cin读入优化
std::ios::sync_with_stdio(false);
string s;
int ans = 0;
cin >> s; //字符串输入
for (int i = 1; i < s.size(); i++) {
if (s[i] != s[i - 1]) ans++; //碰到不一样的就反转一下
}
if (s[s.size() - 1] == '0') cout << ans + 1; // 最后要特判一下 如果最后的是 0 还要多翻一次
else cout << ans; //不是0的话直接输出就好
return 0; //完结撒花。。。,洛谷专用
}