forked from deepanshumishra/JavaAndCPP_programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFLIPSORT.java
More file actions
59 lines (51 loc) · 1.1 KB
/
Copy pathFLIPSORT.java
File metadata and controls
59 lines (51 loc) · 1.1 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
47
48
49
50
51
52
53
54
55
56
57
58
59
package codechef_lib;
import java.util.Scanner;
public class FLIPSORT {
public static void main(String[] args) {
//TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i=1;i<=t;i++) {
int n = sc.nextInt();
String s = sc.next();
char arr[] = s.toCharArray();
boolean cont=false;
int count=0;
for(int j =1;j<n;j++) {
// if(arr[j]==arr[j-1]) {
// cont=true;
// }
// if(cont && arr[j]!=arr[j-1]) {
// arr=flip(0,j-1,arr);
// count++;
// cont=false;
// }else if(!cont && arr[j]!=arr[j-1]){
// arr=flip(0,j-1,arr);
// count++;
// }
if(arr[j]==arr[j-1]) {
cont=true;
}else {
cont=false;
}
if(cont && )
}
//Printing
for(char g:arr) {
System.out.print(g+" ");
}
System.out.println();
System.out.println(count);
}
}
public static char[] flip(int st,int end,char arr[]) {
for(int i=st;i<=end;i++) {
if(arr[i]=='1') {
arr[i]='0';
}else {
arr[i]='1';
}
}
return arr;
}
}