-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
60 lines (53 loc) · 1.07 KB
/
Copy pathMain.java
File metadata and controls
60 lines (53 loc) · 1.07 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
/**
* 백준 1662번
* @author MoonDooo
*/
public class Main {
public static void main(String[] args) {
try {
new CompactString();
}catch(IOException e) {
e.printStackTrace();
}
}
}
class CompactString {
private Stack<Character> stack;
private int result;
public CompactString() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = br.readLine();
stack = new Stack<>();
for(char c : input.toCharArray()) {
stack.add(c);
}
result = 0;
while(stack.size()!=0) {
char c = stack.pop();
if('0'<=c&&c<='9') {
result++;
}else if(c==')') {
result += ExtractString();
}
}
System.out.println(result);
}
public int ExtractString() {
int size=0;
char c;
while((c = stack.pop())!='(') {
if('0'<=c&&c<='9') {
size++;
}
else if(c==')') {
size += ExtractString();
}
}
int num = (int)(stack.pop()-'0');
return num*size;
}
}