forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswe1234.java
More file actions
46 lines (37 loc) · 1.18 KB
/
swe1234.java
File metadata and controls
46 lines (37 loc) · 1.18 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
import java.util.*;
public class swe1234 {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
for (int T = 1; T <= 10; T++) {
sc.next();
String str = sc.next();
String answer = "";
char[] cArr = new char[str.length()];
Stack<Character> Cstack = new Stack<>();
//나눠담기
for(int i =0; i<str.length(); i++)
{
cArr[i] = str.charAt(i);
}
Cstack.push(cArr[0]);
for(int i=1; i<str.length(); i++)
{
try {
if(Cstack.empty())
Cstack.push(cArr[i]);
else if(Cstack.peek() == cArr[i])
Cstack.pop();
else
Cstack.push(cArr[i]);
}catch (Exception e)
{
Cstack.push(cArr[i]);
e.printStackTrace();
}
}
while(!Cstack.empty())
answer = Cstack.pop() + answer;
System.out.println("#" + T + " " + answer);
}
}
}