Repository navigation
Expand file tree
/
Copy pathQ1406_F1.java
More file actions
93 lines (69 loc) · 1.73 KB
/
Copy pathQ1406_F1.java
File metadata and controls
93 lines (69 loc) · 1.73 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
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
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;
import java.util.regex.Pattern;
public class Q1406_F1 {
static List<String> list;
static int cursor;
public static void main(String[] args) {
list = new LinkedList<>();
Scanner scan = new Scanner(System.in);
String[] arr = scan.nextLine().split("");
if (arr.length > 100000)
return;
cursor = arr.length;
System.out.println("Cursor first position: "+cursor +", input size : " + arr.length);
Arrays.stream(arr).filter(str -> Pattern.matches("^[a-z]*$", str)).forEach(str -> list.add(str));
int count = Integer.parseInt(scan.nextLine());
if (count > 500000 || count < 0)
return;
try {
Class clz = Q1406_F1.class;
Object obj = clz.newInstance();
Method method;
for (int i = 0; i < count; i++) {
String[] input = scan.nextLine().split(" ");
if (input.length > 1) {
method = clz.getMethod(input[0], String.class);
method.invoke(obj, input[1]);
} else {
method = clz.getMethod(input[0]);
method.invoke(obj);
}
}
list.forEach(str -> System.out.print(str));
} catch (Exception e) {
e.printStackTrace();
}
}
public void L() {
if(cursor == -1) {
return;
}
cursor--;
}
public void D() {
if(cursor == list.size()) {
return;
}
cursor++;
}
public void B() {
if(cursor == -1 || cursor == 0) {
return;
}
list.remove(cursor-1);
cursor--;
}
public void P(String input) {
if(cursor == -1) {
list.add(0, input);
return;
}
list.add(cursor, input);
cursor++;
}
}