-
Notifications
You must be signed in to change notification settings - Fork 6
/
JIHANEOL.java
81 lines (73 loc) · 1.92 KB
/
JIHANEOL.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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
public class JIHANEOL {
static BufferedReader br;
static StringTokenizer st;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
String word = br.readLine();
String boom = br.readLine();
StringBuilder newWord = new StringBuilder();
Stack<Character> stack = new Stack<>();
for(int i=0; i<word.length(); i++) {
// boom에 포함되었나.
if(boom.contains(""+word.charAt(i))){
// 1. boom에서 마지막 문자면 넣고 스택 확인.
if(boom.charAt(boom.length()-1)==word.charAt(i)) {
stack.add(word.charAt(i));
check(stack,boom);
}else {
// 2. 넣기만 하기
stack.add(word.charAt(i));
}
// 포함 되지 않으면
}else {
// 1. 스택이 남아 있다면 새로운 단어에 넣고 현재 단어 넣기.
if(!stack.isEmpty()) {
for(int j=0; j<stack.size(); j++) {
newWord.append(stack.get(j));
}
stack.clear();
newWord.append( word.charAt(i));
}else {
//2 . 비어 있다면 그냥 넣기
newWord.append(word.charAt(i));
}
}
}
if(!stack.isEmpty()) {
for(int i=0; i<stack.size(); i++) {
newWord.append(stack.get(i));
}
}
if(newWord.toString().equals("")) {
System.out.println("FRULA");
}else {
System.out.println(newWord.toString());
}
}
public static void check(Stack<Character> stack,String boom) {
boolean flag = false;
if(stack.size()>=boom.length()) {
for(int i=0; i<boom.length(); i++) {
if(stack.get(stack.size()-boom.length()+i)!=(boom.charAt(i))){
flag = true;
break;
}
}
}else {
return;
}
if(flag) {
return;
}else {
for(int i=0; i<boom.length(); i++) {
stack.pop();
}
}
}
}