-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzad10_ms.cpp
60 lines (55 loc) · 1 KB
/
zad10_ms.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
#include <iostream>
#include <stack>
using namespace std;
void clear(stack<char> *heap)
{
while (!heap->empty())
{
heap->pop();
}
}
int nawiasy(char arr[])
{
stack<char> heap;
int i = 0;
int curr = 0;
int max = 0;
while (arr[i] != '0')
{
switch (arr[i])
{
case '(':
heap.push('(');
break;
case ')':
if (heap.empty())
{
curr = 0;
clear(&heap);
}
else{
heap.pop();
curr+=2;
}
if (curr > max)
max = curr;
break;
}
i++;
}
return max;
}
int main()
{
string s = " ";
cin >> s[0];
char c = ' ';
while (c != '0' && cin >> c)
{
s += c;
}
char *temp = (char *)malloc((size_t)s.size() * sizeof(char));
for (int i = 0; i < s.size(); i++)
temp[i] = s[i];
cout << nawiasy(temp) << endl;
}