Advertisement
STANAANDREY

Untitled

Jan 11th, 2020
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll int64_t
  4.  
  5. ll a, b;
  6. string s;
  7. unsigned it;
  8.  
  9. inline void evalP(ll& pa, ll& pb)
  10. {
  11. it++;
  12. pa = pb = 0;
  13. while (s[it] != ')' && it < s.size())
  14. {
  15. char let;
  16.  
  17. if (isalpha(s[it]))
  18. let = s[it++];
  19. ll x = 0;
  20. while (isdigit(s[it]))
  21. {
  22. x = x * 10 + ll(s[it] - '0');
  23. it++;
  24. }
  25. if (s[it] == '(')
  26. {
  27. ll ppa, ppb;
  28. evalP(ppa, ppb);
  29. ll x = 0;
  30. it++;
  31. bool hd2 = false;
  32. while (isdigit(s[it]))
  33. {
  34. x = x * 10 + ll(s[it] - '0');
  35. it++;
  36. hd2 = true;
  37. }
  38. if (!hd2)
  39. x = 1;
  40. ppa *= x;
  41. ppb *= x;
  42. pa += ppa;
  43. pb += ppb;
  44. }
  45.  
  46. if (let == 'A')
  47. pa += x;
  48. else
  49. pb += x;
  50. }
  51. }
  52.  
  53. signed main()
  54. {
  55. getline(cin, s);
  56. while (it < s.size())
  57. {
  58. if (s[it] == '(')
  59. {
  60. ll pa, pb;
  61. evalP(pa, pb);
  62. it++;
  63. ll x = 0;
  64. bool hd = false;
  65. while (isdigit(s[it]))
  66. {
  67. x = x * 10 + ll(s[it] - '0');
  68. it++;
  69. hd = true;
  70. }
  71. if (!hd)
  72. x = 1;
  73. a += x * pa;
  74. b += x * pb;
  75. }
  76. char let = s[it++];
  77. ll x = 0;
  78.  
  79. while (isdigit(s[it]) && it < s.size())
  80. {
  81. x = x * 10 + ll(s[it] - '0');
  82. it++;
  83. }
  84. if (let == 'A')
  85. a += x;
  86. else
  87. b += x;
  88. //cerr << a << ' ' << b << endl;
  89. }
  90.  
  91. //cerr<<endl;
  92. cout << a << ' ' << b;
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement