hiho week 164 register

Ended

Participants:394

Verdict:Accepted
Score:100 / 100
Submitted:2017-08-20 02:34:27

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;
int main()
{
    int cases;
    scanf("%d", &cases);
    for (int _case = 0; _case < cases; _case++)
    {
        string str;
        cin >> str;
        int n = str.length(), s = 0;
        for (int i = 0; i < n; i++)
            s += str[i] - '0';
        int ans = n - s, t = 0;
        for (int i = 0; i < n; i++)
        {
            t += str[i] - '0';
            ans = min(ans, t + n - i - 1 - s + t);
        }
        printf("%d\n", ans);
    }
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX