Advertisement
a53

ModificaParanteze

a53
Dec 11th, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. char s[1003];
  5.  
  6. int NrMinOp()
  7. {
  8. int i, cnt = 0, nrOp = 0;
  9. int n = strlen(s);
  10. if (n % 2 == 1) return -1;
  11. for (i = 0; i < n; i++)
  12. {
  13. if (s[i] == '(') cnt++;
  14. else cnt--;
  15.  
  16. if (cnt < 0)
  17. {
  18. nrOp++;
  19. cnt = 1;
  20. }
  21. }
  22. nrOp += cnt / 2;
  23. return nrOp;
  24. }
  25.  
  26. int main()
  27. {
  28. cin >> s;
  29. cout << NrMinOp();
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement