-
Notifications
You must be signed in to change notification settings - Fork 0
/
ANARC09A - Seinfeld.cpp
50 lines (48 loc) · 1.13 KB
/
ANARC09A - Seinfeld.cpp
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
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
using namespace std;
int main()
{
fastread();
int n,test = 1;
string s;
while(1){
cin>>s;
n = s.length();
if(s[0] == '-'){
break;
}
stack<char>st;
for(int i=0; i<n; i++){
if(s[i] == '{'){
st.push(s[i]);
}
else{
if(!st.empty() && st.top() == '{'){
st.pop();
}
else{
st.push(s[i]);
}
}
}
cout<<test<<". ";
test++;
int c = 0;
while(!st.empty()){
char a,b;
a = st.top(),st.pop();
b = st.top(),st.pop();
if(a == '{' && b == '}')c+=2;
else{
c++;
}
}
cout<<c<<endl;
}
return 0;
}