Saleh127

cf 1373C

Jun 26th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. int main()
  6. {
  7. test
  8. {
  9. string s;
  10. cin>>s;
  11. ll i,j,k=0,l=s.size(),cur=0,d;
  12. for(j=0;j<l;j++)
  13. {
  14. if (s[j] == '+')
  15. {
  16. cur++;
  17. }
  18. else
  19. {
  20. cur--;
  21. }
  22. if (cur < 0)
  23. {
  24. k+=(j+1);
  25. cur=0;
  26. }
  27. }
  28. k+=l;
  29. cout<<k<<endl;
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment