Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream fin("paranteze2.in");
  5. ofstream fout("paranteze2.out");
  6.  
  7. char s[260];
  8. int st[1000];
  9. int n, top;
  10. int main()
  11. {
  12. int i, x;
  13. fin >> s;
  14. for(i = 0;s[i];i++)
  15. {
  16. if(s[i] == '(')
  17. st[++top] = -1;
  18. else
  19. {
  20. if(st[top]> 0)
  21. {
  22. x = st[top];
  23. top--;
  24. }
  25. else
  26. x = 0;
  27. ///acum in vf stivei este sigur -1;
  28. top--;
  29. x++;
  30. ///cazul 1 stiva e vida sau paranteza in vf
  31. if(top == 0 || st[top] == -1)
  32. st[++top] = x;
  33. ///caz 2 in vf stivei este un nr
  34. else
  35. st[top] = max(x, st[top]);
  36. }
  37. }
  38. fout << st[top];
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement