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 Heartbeat
GNU G++17
12 ms
1.2 MB
Accepted