CSES - Datatähti 2019 loppu - Results
Submission details
Task:Bittijono
Sender:Kerkko Konola
Submission time:2019-01-17 16:22:43 +0200
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:16:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int it = 0; it < ui.length(); it++) {
                      ~~~^~~~~~~~~~~~~
input/code.cpp:28:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int it = 1; it < ui.length(); it++) {
                      ~~~^~~~~~~~~~~~~
input/code.cpp:41:9: error: expected ';' before '}' token
         }
         ^

Code

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <math.h>

using namespace std;

int main() {
    string ui;
    cin >> ui;
    int ykkoset = 0;
    int parit = 0;
    int ans = 0;
    for (int it = 0; it < ui.length(); it++) {
        if (ui[it] == '1') {
            ykkoset += 1;
        }
        if (ykkoset % 2 == 0) {
            parit += 1;
            ans += parit;
        }
    }
    
    ykkoset = 0;
    parit = 0;
    for (int it = 1; it < ui.length(); it++) {
        if (ui[it] == '1') {
            ykkoset += 1;
        }
        if (ykkoset % 2 == 0) {
            parit += 1;
            ans += parit;
        }
    }
    
    for (auto i:ui) {
        if (i == '0') {
            ans += 1
        }
    }
    cout << ans << endl;
    
    return 0;
}