-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
32 lines (25 loc) · 786 Bytes
/
Main.java
File metadata and controls
32 lines (25 loc) · 786 Bytes
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
32
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String S = sc.next();
int cnt0 = 0;
int cnt1 = 0;
if(S.charAt(0) == '1') cnt0++;
else cnt1++;
for(int i=0; i<S.length()-1; i++){
if(S.charAt(i) != S.charAt(i+1)){
if(S.charAt(i+1) == '1'){
// case1 : every number will turn to 0.
// if the next num is 1, then flip it.
cnt0++;
} else {
// case2 : every number will turn to 1.
cnt1++;
}
}
}
System.out.println(Math.min(cnt0, cnt1));
sc.close();
}
}