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

Ended

Participants:118

Verdict:Accepted
Score:100 / 100
Submitted:2016-06-24 16:36:48

Lang:Java

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
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        while (n > 0) {
            char[] s = in.next().toCharArray();
            int cost = 0;
            for (int i = 0i < s.lengthi++) {
                if (s[i== '0') {
                    cost++;
                }
            }
            int minCost = cost;
            for (int i = 0i < s.lengthi++) {
                if (s[i== '0') {
                    cost = cost - 1;
                } else {
                    cost = cost + 1;
                }
                minCost = Math.min(costminCost);
            }
            System.out.println(minCost);
            n--;
        }
    }
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX