-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_P307.cpp
53 lines (51 loc) · 1019 Bytes
/
2_P307.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
51
52
53
#include<bits/stdc++.h>
using namespace std;
char stk[10005];
bool isBrace(char c)
{
if(c == '(') return 1;
if(c == ')') return 1;
if(c == '[') return 1;
if(c == ']') return 1;
if(c == '{') return 1;
if(c == '}') return 1;
return 0;
}
char myPair(char c)
{
if(c == ')') return '(';
if(c == ']') return '[';
if(c == '}') return '{';
}
int main()
{
string s = "";
char c;
while(c = getchar())
{
if(c == EOF) break;
if(isBrace(c)) s += c;
}
int top = -1;
for(int i = 0; i < s.size(); i++)
{
char t = s[i];
if(t == '(' || t == '[' || t == '{')
{
stk[++top] = t;
} else if(t == ')' || t == ']' || t == '}')
{
if(stk[top] == myPair(t))
{
top--;
}else
{
cout << "wrong";
return 0;
}
}
}
if(top == -1) cout << "right";
else cout << "wrong";
return 0;
}