-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSW expert-괄호 짝짓기.cpp.txt
69 lines (66 loc) · 989 Bytes
/
SW expert-괄호 짝짓기.cpp.txt
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
#include <iostream>
#include<stack>
#include<string>
using namespace std;
int main()
{
int testcase,countT;
testcase = 10;
countT = 1;
while (testcase!=0)
{
bool end = false;
string s;
stack<char> st;
int num;
cin >> num;
for (int i = 0; i < num; i++)
{
char c;
cin >> c;
if (c == '(' || c == '[' || c == '{' || c == '<')
{
st.push(c);
}
else if (c == ')' || c == ']' || c == '}' || c == '>')
{
if (st.empty())
{
end = true;
break;
}
if (c == ')'&&st.top()=='(')
{
st.pop();
}
else if (c == ']'&&st.top() == '[')
{
st.pop();
}
else if (c == '}'&&st.top() == '{')
{
st.pop();
}
else if (c == '>'&&st.top() == '<')
{
st.pop();
}
else
{
end = true;
break;
}
}
}
if (!end&&st.empty())
{
cout <<"#"<<countT++<<" 1" << endl;
}
else
{
cin >> s;
cout << "#" << countT++ << " 0" << endl;
}
testcase--;
}
}