hihoCoder太阁最新面经算法竞赛5 register

Ended

Participants:118

Verdict:Accepted
Score:100 / 100
Submitted:2016-06-19 12:16:37

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
24
25
26
27
28
// hihoder 01
#include<bits/stdc++.h>
using namespace std;
int cal(string s,int i)
{
    int res=0;
    for(int j=0;j<s.length();++j)
    {
        if(j<i&&s[j]!='0')res++;
        if(j>i&&s[j]!='1')res++;
    }
    return res;
}
int main()
{
    int t;cin>>t;
    while(t--)
    {
        string s;cin>>s;
        int res=INT_MAX;
        for(int i=0;i<s.length();++i)
        {
            res=min(res,cal(s,i));
        }
        cout<<res<<endl;
    } 
    return 0;
} 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX