๋ด ํ์ด
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Scanner;
import java.util.Stack;
import java.util.HashMap;
import java.util.ArrayList;
public class Main {
// ๋ฌธ์ ๋ณ๋ก ์์น ์ ์ฅ
static HashMap<Character, ArrayList<Integer>> characterMaps = new HashMap<Character, ArrayList<Integer>>();
static Stack<Character> stack = new Stack<Character>();
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String text = br.readLine();
String find = br.readLine();
// stack์ ํ ๋ฌธ์์ด ์ฉ push
for (int i = 0; i < text.length(); i++) {
// if(characterMaps.containsKey(text.charAt(i))){
char key = text.charAt(i);
stack.push(key);
if (checkIfExists(stack, find)) {
for (int t = 0; t < find.length(); t++) {
stack.pop();
}
}
}
// ๋ฐฐ์ด string ์ผ๋ก ๋ง๋ค๊ธฐ
StringBuilder sb = new StringBuilder();
for (int i = 0; i < stack.size(); i++) {
sb.append(stack.get(i));
}
String answer = sb.toString();
System.out.println((answer.length() == 0) ? "FRULA" : answer);
}
public static boolean checkIfExists(Stack<Character> stack, String find) {
boolean result = true;
if (stack.size() >= find.length()) {
int index = stack.size() - find.length();
for (int i = 0; i < find.length(); i++) {
if (find.charAt(i) != stack.get(index + i)) {
result = false;
break;
}
}
}
else {
result = false;
}
return result;
}
}
๋ฌธ์ ๋ฅผ ์์ ํ ์๋ชป ์ดํดํด์ ์๋ ์์์์ 1,2,a,b ๋ฅผ ๊ฐ๊ฐ ํ์ธํ๋ ํ์ด๋ก ์์ฑํ๋๋ฐ, ๊ณ์ 2ํ๋ก ๋์์ ์คํจํด์ ๊ฐ์ก๊ณ ๋ค์ ๋ณด๋ 12ab์์ฒด๋ฅผ ํ์ธํด์ ํญ๋ฐ์ํค๋ ๋ฌธ์ ์๋ค.
12ab112ab2ab
12ab
์ฐธ๊ณ : char array ๋ก ํธ๋ ๋ฐฉ๋ฒ ํ์ด
๋ฐ์ํ
'๐ค ์๊ณ ๋ฆฌ์ฆ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
baekjoon. ํํฐ (0) | 2022.10.07 |
---|---|
baekjoon. ๋ ๊ฒ์ (0) | 2022.08.31 |
programmers. ๋ค๋จ๊ณ ์นซ์ ํ๋งค (0) | 2022.06.29 |
์๊ณ ๋ฆฌ์ฆ ๊ฟํ. ์๋ฐ (0) | 2022.06.27 |
programmers. ํ๋ ฌ ํ ๋๋ฆฌ ํ์ ํ๊ธฐ (0) | 2022.06.26 |