forked from Advanced-Programming-Course/Midterm-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.java
107 lines (105 loc) · 3.24 KB
/
Node.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
public class Node {
public String arrow;
public int num;
public String color;
public String result;
public Node(String arrow, int num, String color) {
this.arrow = arrow;
this.num = num;
this.color = color;
}
public String White(String str1, String str2) {
StringBuilder result = new StringBuilder();
int len1 = str1.length();
int len2 = str2.length();
if (this.num == 1) {
for (int m = 0; m < Math.max(len1, len2); m++) {
if (m < len1) {
result.append(str1.charAt(m));
}
if (m < len2) {
result.append(str2.charAt(m));
}
}
}
else if (num == 2) {
result.append(str1);
result.append(new StringBuilder(str2).reverse());
}
else if (num == 3) {
for (int m = 0; m < Math.max(len1, len2); m++) {
if (m < len1) {
result.append(str1.charAt(m));
}
if (m < len2) {
result.append(str2.charAt(len2 - 1 - m));
}
}
}
else if (num == 4) {
if (len1 % 2 == 0) {
return str1;
} else {
return str2;
}
}
else if (num == 5) {
int minLength = Math.min(len1, len2);
for (int m = 0; m < minLength; m++) {
char char1 = str1.charAt(m);
char char2 = str2.charAt(m);
int sum = (char1 - 'a' + char2 - 'a') % 26 + 'a';
result.append((char) sum);
}
if (len1 > len2) {
result.append(str1.substring(len2));
}
else if (len2 > len1) {
result.append(str2.substring(len1));
}
}
else {
return "";
}
return result.toString();
}
public String Black(String str1) {
StringBuilder result = new StringBuilder();
if (num == 1) {
result.append(new StringBuilder(str1).reverse());
}
else if (num == 2) {
for (char ch : str1.toCharArray()) {
result.append(ch).append(ch);
}
}
else if (num == 3) {
result.append(str1).append(str1);
}
else if (num == 4) {
if (str1.length() > 1) {
result.append(str1.substring(1)).append(str1.charAt(0));
}
else {
result.append(str1);
}
}
else if (num == 5) {
for (char ch : str1.toCharArray()) {
if (Character.isLowerCase(ch)) {
result.append((char) ('z' - (ch - 'a')));
}
else if (Character.isUpperCase(ch)) {
result.append((char) ('Z' - (ch - 'A')));
}
else {
result.append(ch);
}
}
}
else {
result.append(str1);
}
return result.toString();
}
}