Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- by: senb1 aka amigo
- */
- #include <bits/stdc++.h>
- using namespace std;
- typedef unsigned long long ull;
- typedef long long ll;
- #define all(x) x.begin(), x.end()
- #define endl '\n'
- const ll maxn = 50;
- const ll inf = 5e5 + 6;
- const ll mod = 2021;
- int main() {
- std::ios::sync_with_stdio(0);
- std::cin.tie(0);
- string s;
- cin >> s;
- int b = 0, ans = 0, ind = 0;
- for (int i = 0; i < s.size(); i++) {
- if (s[i] == '(') {
- b++;
- // cout << "B++!! " << b << endl;
- } else if (s[i] == ')') {
- b--;
- ind = i;
- } else if (s[i] == 'X')
- continue;
- else
- continue;
- if (b < 0) {
- // cout << "b < 0 " << b << ' ' << ind << endl;
- int jj = 0;
- for (int j = ind; j < s.size(); j++)
- if (s[j] == '(') {
- jj = j;
- break;
- }
- while (jj > ind) {
- swap(s[jj], s[jj - 1]);
- jj--;
- ans++;
- }
- swap(s[jj], s[jj + 1]);
- }
- // cout << i << ' ' << b << ' ' << s << ' ' << ans << endl;
- }
- cout << ans << endl;
- }
- /*
- )()(
- )))(((
- ))()((
- )())((
- ()))((
- ())()(
- ()())(
- ()()()
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement