Skip to content

Commit 2ee7f80

Browse files
authored
Merge pull request #124 from LEEHYUNDONG/main
220808/이현동
2 parents aa5a80d + 7a5f97d commit 2ee7f80

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
56.3 KB
Binary file not shown.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
using namespace std;
5+
6+
bool visited[51] = {
7+
false,
8+
};
9+
10+
int dfs(string &s, int idx)
11+
{
12+
int cnt = 0;
13+
for (int i = idx; i < s.size(); i++)
14+
{
15+
if (s[i] == '(' && !visited[i])
16+
{
17+
visited[i] = true;
18+
int num = s[i - 1] - '0';
19+
cnt--;
20+
cnt += num * dfs(s, i + 1);
21+
}
22+
else if (s[i] == ')' && !visited[i])
23+
{
24+
visited[i] = true;
25+
return cnt;
26+
}
27+
else if (!visited[i])
28+
{
29+
visited[i] = true;
30+
cnt++;
31+
}
32+
}
33+
34+
return cnt;
35+
}
36+
int main()
37+
{
38+
string s;
39+
cin >> s;
40+
int ans = dfs(s, 0);
41+
cout << ans << endl;
42+
43+
return 0;
44+
}

0 commit comments

Comments
 (0)