-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringBrackets.cpp
More file actions
57 lines (53 loc) · 902 Bytes
/
stringBrackets.cpp
File metadata and controls
57 lines (53 loc) · 902 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
48
49
50
51
52
53
54
55
#include<iostream>
using namespace std;
int main()
{
int a[3]={0,0,0};
int current[10],i,top=-1;
string s,ans="incorrect";
cin>>s;
for(i=0;i<s.length();i++)
{
if(s[i]=='[')
{
a[0]++;
top++;
current[top]=0;
}
else if(s[i]=='(')
{
a[1]++;
top++;
current[top]=1;
}
else if(s[i]=='{')
{
a[2]++;
top++;
current[top]=2;
}
else if(s[i]==']'&¤t[top]==0)
{
a[0]--;
top--;
}
else if(s[i]==')'&¤t[top]==1)
{
a[1]--;
top--;
}
else if(s[i]=='}'&¤t[top]==2)
{
a[2]--;
top--;
}
else break;
if(i==s.length()-1)
{
if(a[0]==0&&a[1]==0&&a[2]==0)
ans="correct";
else ans="incorrect";
}
}
cout<<ans;
}