Source Code
#include <bits/stdc++.h>

using namespace std;

int main() {
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '1') {
            ans++;
        } else {
            if (i >= 1 && i + 1 < s.size() && min(s[i + 1], s[i - 1]) == '1') {
                ans++;
            }
        }
    }
    cout << ans << '\n';
	return 0;
}
Copy
Japanese holidays Mohamedmaher
GNU G++17
5 ms
1.1 MB
Accepted