-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFlipBits.java
More file actions
46 lines (34 loc) · 1.19 KB
/
FlipBits.java
File metadata and controls
46 lines (34 loc) · 1.19 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.lang.*;
import java.io.*;
import java.util.*;
import java.math.*;
class FlipBits {
public static void main(String [] args ) {
Scanner sc = new Scanner (System.in);
int t = sc.nextInt();
sc.nextLine();
while ( t-- > 0) {
String s = sc.nextLine();
char [] array = s.toCharArray();
char [] array1 = new char[s.length()];
char [] array0 = new char[s.length()];
int counter0 = 0;
int counter1 = 0;
for ( int i = 0; i < s.length(); i++ ) {
if ( i % 2 == 0 ) {
array1[i] = '1';
array0[i] = '0';
}
else{
array1[i] = '0';
array0[i] = '1';
}
if ( array[i] != array0[i] )
counter0++;
if ( array[i] != array1[i] )
counter1++;
}
System.out.println( Math.min( counter0, counter1 ) );
}
}
}