Advertisement
jakaria_hossain

codeforces - pluses and minuses

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