forked from pranavanurag/SPOJSolutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathANARC09A.cpp
More file actions
47 lines (39 loc) · 656 Bytes
/
Copy pathANARC09A.cpp
File metadata and controls
47 lines (39 loc) · 656 Bytes
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
#include <iostream>
#include <stack>
using namespace std;
stack<char> S;
int main()
{
ios::sync_with_stdio(false);
string x;
int c = 1;
while (cin>>x && x[0] != '-')
{
S.push(x[0]);
for (int i = 1; i < x.size(); i++)
if (!S.empty() && S.top() == '{' && x[i] == '}')
S.pop();
else
S.push(x[i]);
int ans = 0;
while (!S.empty())
{
char x = S.top();
S.pop();
if (S.empty())
{
ans++;
break;
}
char y = S.top();
S.pop();
if (x == '{' && y == '}')
ans += 2;
else if ((x == '{' && y == '{' ) || (x == '}' && y == '}'))
ans += 1;
}
cout<<c<<". "<<ans<<endl;
c++;
}
return 0;
}