题库 信息学奥赛题库 题目列表 NOIP 2017普及组初赛试题 阅读程序写结果#include<...
填空题

NOIP 2017普及组初赛试题 阅读程序写结果

#include<iostream>
using namespacestd;
int main() {
    string ch;
    int a[200];
    int b[200];
    int n, i, t, res;
    cin >> ch;
    n = ch.length();
    for (i = 0; i < 200; i++)
        b[i] = 0;
    for (i = 1; i <= n; i++) {
        a[i] = ch[i - 1] - '0';
        b[i] = b[i - 1] + a[i];
}
    res = b[n]; 
    t = 0;
    for (i = n; i > 0; i--) {
        if (a[i] == 0)
            t++;
        if (b[i - 1] + t < res)
            res = b[i - 1] + t;
    }
    cout << res << endl;
    return 0;
}

输入: 1001101011001101101011110001

输出: ___

题目信息
2017年 初赛 阅读程序
-
正确率
0
评论
124
点击