-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path210318_BOJ_1662.cpp
More file actions
82 lines (70 loc) · 1.16 KB
/
Copy path210318_BOJ_1662.cpp
File metadata and controls
82 lines (70 loc) · 1.16 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
#include <iostream>
#include <string>
using namespace std;
string s;
pair<int, int> findAnswer(int start) {
int count = 0;
int i = start;
for (; i < s.size(); ++i) {
if ('0' <= s[i] && s[i] <= '9') {
if (s[i + 1] == '(') {
pair<int, int> p = findAnswer(i + 2);
count = count + (s[i] - '0') * p.first;
i = p.second;
}
else
count++;
}
else if (s[i] == ')')
return { count, i };
}
return {count, i};
}
int main() {
cin >> s;
cout << findAnswer(0).first << "\n";
return 0;
}
//#include <iostream>
//#include <string>
//
//using namespace std;
//
//string s;
//
//void expandString(int index) {
//
// int mul = s[index - 1] - '0';
//
// int i = index + 1;
// string t, t3;
// while (s[i] != ')') {
// t.push_back(s[i++]);
// }
//
// string t2;
// for (int j = 0; j < mul; ++j)
// t2 = t2 + t;
//
// t = s.substr(0, index - 1);
// t3 = s.substr(i + 1, s.size() - i - 1);
//
// s = t + t2 + t3;
//}
//
//int main() {
//
// cin >> s;
//
// for (int i = s.size() - 1; i >= 0; --i) {
// if ('1' <= s[i] && s[i] <= '9') {
// if (s[i + 1] == '(') {
// expandString(i + 1);
// }
// }
// }
//
// cout << s.size() << "\n";
//
// return 0;
//}