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

Ended

Participants:118

Verdict:Accepted
Score:100 / 100
Submitted:2016-06-21 17:05:10

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
29
30
31
#include <iostream> 
#include <cstdio> 
#include <cstring> 
#include <cstdlib> 
using namespace std; 
const int maxn = 1000; 
int main(){
    int test_num, len,  i, cnt, z_cn, tmp, ans; 
    char ch[maxn]; 
    scanf("%d", &test_num); 
    while(test_num--){
        scanf("%s", ch); 
        len = strlen(ch); 
        z_cn = 0; 
        for(i=0; i<len; i++){
            if(ch[i] == '0'){ z_cn++; }
        }
        cnt = 0; ans = 0x3f3f3f3f; 
        for(i=0; i<len; i++){
            if(ch[i] == '1'){
                tmp = cnt + (z_cn - (i - cnt)); 
                cnt++; 
            }else{
                tmp = cnt + (z_cn - (i + 1 - cnt)); 
            }
            if(tmp < ans){
                ans = tmp; 
            }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX