-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnesting.cpp
More file actions
55 lines (52 loc) · 1.23 KB
/
nesting.cpp
File metadata and controls
55 lines (52 loc) · 1.23 KB
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
// you can use includes, for example:
// #include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
int squigly_bracket = 0;
int square_bracket = 0;
int round_bracket = 0;
char latest = '0';
if(S.empty())
return 1;
else
{
int x = 0;
while((round_bracket >= 0))
{
if((int)S[x] == 40)
{
round_bracket++;
latest = '(';
//break;
}
if((int)S[x] == 41)
{
round_bracket--;
if((latest != '(')&&(latest != '0'))
break;
else
latest = '0';
//break;
}
if(x == strlen(S.c_str()))
{
if((round_bracket == 0))
{
return 1;
}
else
{
return 0;
}
}
x++;
}
//loop through string
return 0;
}
}