Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("paranteze2.in");
- ofstream fout("paranteze2.out");
- char s[260];
- int st[1000];
- int n, top;
- int main()
- {
- int i, x;
- fin >> s;
- for(i = 0;s[i];i++)
- {
- if(s[i] == '(')
- st[++top] = -1;
- else
- {
- if(st[top]> 0)
- {
- x = st[top];
- top--;
- }
- else
- x = 0;
- ///acum in vf stivei este sigur -1;
- top--;
- x++;
- ///cazul 1 stiva e vida sau paranteza in vf
- if(top == 0 || st[top] == -1)
- st[++top] = x;
- ///caz 2 in vf stivei este un nr
- else
- st[top] = max(x, st[top]);
- }
- }
- fout << st[top];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement