-
Notifications
You must be signed in to change notification settings - Fork 54
/
pranthesis.cpp
61 lines (54 loc) · 931 Bytes
/
pranthesis.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
54
55
56
57
58
59
60
61
#include<iostream>
#include<string.h>
using namespace std;
void checkFlag(char i ,char j,int *flag){
if(i=='[' && (j=='}' || j==')')){
*flag=1;
}
if(i=='{' && (j==']' || j==')')){
*flag=1;
}
if(i=='(' && (j==']' || j=='}')){
*flag=1;
}
}
int main()
{
int t;
cin>>t;
while(t--){
string s;
cin>>s;
int flag=0;
int count_circ=0;
int count_rect=0;
int count_curl=0;
for(int i=0;i<s.length();i++){
if(i<s.length()-1){
checkFlag(s[i],s[i+1],&flag);
}
if(flag==1){
break;
}
if(s[i]=='{'){
count_curl++;
}else if(s[i]=='}'){
count_curl--;
}else if(s[i]=='['){
count_rect++;
}else if(s[i]==']'){
count_rect--;
}else if(s[i]=='('){
count_circ++;
}else if(s[i]==')'){
count_circ--;
}
}
if(flag==0 && count_circ==0 && count_rect==0 && count_curl==0){
printf("Correct\n");
}else{
printf("Incorrect\n");
}
}
return 0;
}