-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringRec.java
More file actions
62 lines (50 loc) · 1.33 KB
/
Copy pathStringRec.java
File metadata and controls
62 lines (50 loc) · 1.33 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
60
61
62
public class StringRec {
public static void main(String[] args){
System.out.println(skipAppnotApple("bacappcappledaha"));
}
static void skip(String p, String up){
if(up.isEmpty()){
System.out.println(p);
return;
}
char ch = up.charAt(0);
if(ch == 'a'){
skip(p, up.substring(1));
}else{
skip(p + ch, up.substring(1));
}
}
static String skip1(String up){
if(up.isEmpty()){
return "";
}
char ch = up.charAt(0);
if(ch == 'a'){
return skip1(up.substring(1));
}else{
return ch + skip1(up.substring(1));
}
}
static String skipApple(String up){
if(up.isEmpty()){
return "";
}
char ch = up.charAt(0);
if(up.startsWith("apple")){
return skipApple(up.substring(5));
}else{
return ch + skipApple(up.substring(1));
}
}
static String skipAppnotApple(String up){
if(up.isEmpty()){
return "";
}
char ch = up.charAt(0);
if(up.startsWith("app") && !up.startsWith("apple")){
return skipAppnotApple(up.substring(3));
}else{
return ch + skipAppnotApple(up.substring(1));
}
}
}