Source Code
#include <iostream>
using namespace std;

int main() {
    string s;
    cin>>s;
    int n = s.length();     
    int ans = 0;
    for(int i = 0; i<n; i++){
        if(s[i]=='1'){
            ans++;
        } else if(i > 0 && i < n-1 && s[i-1]=='1' && s[i+1]== '1'){
            ans++;
        }
    }
    cout<<ans;
    return 0;
}
Copy
Japanese holidays osaidz7
GNU G++17
6 ms
1.3 MB
Accepted