forked from defia-soft/CodingCompetition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Java.java
108 lines (102 loc) · 1.85 KB
/
Java.java
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
public class ContestApplication {
public static void main(String[] args) {
// Task 1: Refactor mix method
List<String> input = mix(1000000);
// Task 2: Implement sortAndPrint method
sortAndPrint(input);
return 0;
}
public static sortAndPrint(){
// TODO You are expected to sort the list in the order of r-g-b
// and print the sorted list
}
public static List<String> mix(int i) {
// TODO You are expected to refactor mix and convertS methods.
// The main targets are "Efficiency" and "Readibility".
// You are free to change everything.
List<String> j = new ArrayList<>();
while (i > 0) {
String s = "#";
Random r = new Random();
int c1 = r.nextInt(16);
String s1;
s1 = convertS(c1);
s += s1;
int c2 = r.nextInt(16);
String s2;
s2 = convertS(c2);
s += s2;
int c3 = r.nextInt(16);
String s3;
s3 = convertS(c3);
s += s3;
int c4 = r.nextInt(16);
String s4;
s4 = convertS(c4);
s += s4;
int c5 = r.nextInt(16);
String s5;
s5 = convertS(c5);
s += s5;
int c6 = r.nextInt(16);
String s6;
s6 = convertS(c6);
s += s6;
j.add(s);
--i;
}
return j;
}
public static String convertS(int c1) {
String s1;
if (c1 == 0) {
s1 = "0";
}
if (c1 == 1) {
s1 = "1";
}
if (c1 == 2) {
s1 = "2";
}
if (c1 == 3) {
s1 = "3";
}
if (c1 == 4) {
s1 = "4";
}
if (c1 == 5) {
s1 = "5";
}
if (c1 == 6) {
s1 = "6";
}
if (c1 == 7) {
s1 = "7";
}
if (c1 == 8) {
s1 = "8";
}
if (c1 == 9) {
s1 = "9";
}
if (c1 == 10) {
s1 = "A";
}
if (c1 == 11) {
s1 = "B";
}
if (c1 == 12) {
s1 = "C";
}
if (c1 == 13) {
s1 = "D";
}
if (c1 == 14) {
s1 = "E";
}
if (c1 == 15) {
s1 = "F";
}
return s1;
}
}