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

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:12:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int alku = 0; alku < ui.length(); alku++) {
                        ~~~~~^~~~~~~~~~~~~
input/code.cpp:14:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int loppu = alku; loppu < ui.length(); loppu++) {
                                ~~~~~~^~~~~~~~~~~~~
input/code.cpp:15:30: warning: comparison with string literal results in unspecified behavior [-Waddress]
             if (ui[loppu] == "1") {
                              ^~~
input/code.cpp:15:30: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]

Code

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    string ui;
    cin >> ui;
    int ans = 0;
    for (int alku = 0; alku < ui.length(); alku++) {
        int lkm = 0;
        for (int loppu = alku; loppu < ui.length(); loppu++) {
            if (ui[loppu] == "1") {
                lkm++;
            } else if (lkm % 2 == 0) {
                ans += 1;
            }
        }
        ans += int(lkm/2);
    }
    cout << ans << endl;
    return 0;
}