-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem3MysteryBinary.java
More file actions
59 lines (47 loc) · 1.42 KB
/
Problem3MysteryBinary.java
File metadata and controls
59 lines (47 loc) · 1.42 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
import java.util.ArrayList;
public class Problem3MysteryBinary {
static ArrayList<Integer> list1 = new ArrayList<>();
static ArrayList<Integer> list2 = new ArrayList<>();
static int count = 0;
public static void main(String[] args) {
String[] elements = args[0].split("(?!^)");
for(String input : elements)
list1.add( Integer.parseInt( input ));
for( int i = 0; i < 5 ; i++) {
for(int j = 0; j < list1.size() ; j++) {
if ( j+1 == list1.size() ){
workWith( j, true ); //last number true
break;
}
else if ( list1.get(j).intValue() == list1.get(j+1).intValue() )
count++;
else
workWith ( j, false ); //last num false
}//end inner for
System.out.println();
}//end outer for
}//end main
static void workWith( int numberAtIndex, boolean lastNumber ) {
count++;
//System.out.println("\ndbg:\n*count++= " + count);
list2.add(count);
list2.add( list1.get(numberAtIndex) );
//output to the row
System.out.print(count);
System.out.print( list1.get(numberAtIndex) );
//reset count
count = 0;
if (lastNumber){
//reset count and lists
list1 = new ArrayList<>( list2 );
list2.clear();
System.out.println();
count = 0;
}
}
static void printList(int n){
System.out.println("**list" + n+ "**");
for(Integer k: (n==1?list1:list2)) System.out.print(k);
System.out.println();
}
}