Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll int64_t
- ll a, b;
- string s;
- unsigned it;
- inline void evalP(ll& pa, ll& pb)
- {
- it++;
- pa = pb = 0;
- while (s[it] != ')' && it < s.size())
- {
- char let;
- if (isalpha(s[it]))
- let = s[it++];
- ll x = 0;
- while (isdigit(s[it]))
- {
- x = x * 10 + ll(s[it] - '0');
- it++;
- }
- if (s[it] == '(')
- {
- ll ppa, ppb;
- evalP(ppa, ppb);
- ll x = 0;
- it++;
- bool hd2 = false;
- while (isdigit(s[it]))
- {
- x = x * 10 + ll(s[it] - '0');
- it++;
- hd2 = true;
- }
- if (!hd2)
- x = 1;
- ppa *= x;
- ppb *= x;
- pa += ppa;
- pb += ppb;
- }
- if (let == 'A')
- pa += x;
- else
- pb += x;
- }
- }
- signed main()
- {
- getline(cin, s);
- while (it < s.size())
- {
- if (s[it] == '(')
- {
- ll pa, pb;
- evalP(pa, pb);
- it++;
- ll x = 0;
- bool hd = false;
- while (isdigit(s[it]))
- {
- x = x * 10 + ll(s[it] - '0');
- it++;
- hd = true;
- }
- if (!hd)
- x = 1;
- a += x * pa;
- b += x * pb;
- }
- char let = s[it++];
- ll x = 0;
- while (isdigit(s[it]) && it < s.size())
- {
- x = x * 10 + ll(s[it] - '0');
- it++;
- }
- if (let == 'A')
- a += x;
- else
- b += x;
- //cerr << a << ' ' << b << endl;
- }
- //cerr<<endl;
- cout << a << ' ' << b;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement