fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <string.h>
  5. #include <bits/stdc++.h>
  6. #include <cstdlib>
  7. #include <time.h>
  8. #include <fstream>
  9. #include <iterator>
  10. #include <utility>
  11. #include <algorithm>
  12. #include <set>
  13. #include <map>
  14. #include <bitset>
  15. using namespace std;
  16.  
  17. #define ll long long
  18. #define ld long double
  19. typedef vector<int> vi;
  20. typedef multiset<int> mi;
  21. typedef multiset<ll> mll;
  22. typedef vector<ll> vll;
  23. typedef vector<bool> vb;
  24. typedef vector<vector<int>> _2vi;
  25. typedef vector<vector<ll>> _2vll;
  26. #define all(v) ((v).begin()), ((v).end())
  27. #define sz(v) ((ll)((v).size()))
  28.  
  29. #define vinp(v, n) \
  30.   for (ll i = 0; i < (n); i++) \
  31.   cin >> (v)[i]
  32. #define printv(v) \
  33.   for (auto i : (v)) \
  34.   cout << i << " "
  35. #define Bustany \
  36.   ios::sync_with_stdio(0); \
  37.   cin.tie(0); \
  38.   cout.tie(0);
  39. #define fr0(i, n) for (int(i) = 0; (i) < (n); (i)++)
  40. #define fr1(i, n) for (int(i) = 1; (i) < (n); (i)++)
  41. #define _CRT_SECURE_NO_WARNING
  42. const ll MOD = 1000000007;
  43.  
  44. void solve()
  45. {
  46. ll t;
  47. cin >> t;
  48. cin.ignore();
  49. map<string, int> mp;
  50. while (t--)
  51. {
  52. string s;
  53. getline(cin, s);
  54. stringstream ss(s);
  55. string x;
  56. ss >> x;
  57. if (x == "print")
  58. {
  59. string o = "", q;
  60. while (ss >> q)
  61. {
  62. o += q;
  63. o += " ";
  64. }
  65. o.pop_back();
  66. bool brac = false;
  67. string a = "";
  68. for (int i = 0; i < o.size(); i++)
  69. {
  70. if (o[i] == '(')
  71. {
  72. brac = true;
  73. }
  74. else if (o[i] == ')')
  75. {
  76. brac = false;
  77. }
  78. else if (brac)
  79. {
  80. cout << o[i];
  81. }
  82. else if (o[i] == '+')
  83. {
  84. if (!a.empty())
  85. {
  86. if (mp[a] != 0)
  87. {
  88. cout << mp[a];
  89. }
  90. else
  91. {
  92. cout << a;
  93. }
  94. }
  95. a = "";
  96. }
  97. else
  98. {
  99. a += o[i];
  100. }
  101. }
  102. cout << endl;
  103. }
  104. else if (x == "var")
  105. {
  106. ss >> x;
  107. ll y = 0;
  108. string one;
  109. ss >> one;
  110. ss >> one;
  111. if (mp[one] == 0)
  112. {
  113. y += (stoll(one));
  114. }
  115. else
  116. {
  117. y += mp[one];
  118. }
  119. string op;
  120. while (ss >> op)
  121. {
  122. string two;
  123. ss >> two;
  124. if (op == "+")
  125. {
  126. if (mp[two] == 0)
  127. {
  128. y += stoll(two);
  129. }
  130. else
  131. {
  132. y += mp[two];
  133. }
  134. }
  135. else
  136. {
  137. if (mp[two] == 0)
  138. {
  139. y -= stoll(two);
  140. }
  141. else
  142. {
  143. y -= mp[two];
  144. }
  145. }
  146. }
  147. mp[x] = y;
  148. }
  149. else
  150. {
  151. ll y = 0;
  152. string one;
  153. ss >> one;
  154. ss >> one;
  155. if (mp[one] == 0)
  156. {
  157. y += (stoll(one));
  158. }
  159. else
  160. {
  161. y += mp[one];
  162. }
  163. string op;
  164. while (ss >> op)
  165. {
  166. string two;
  167. ss >> two;
  168. if (op == "+")
  169. {
  170. if (mp[two] == 0)
  171. {
  172. y += stoll(two);
  173. }
  174. else
  175. {
  176. y += mp[two];
  177. }
  178. }
  179. else
  180. {
  181. if (mp[two] == 0)
  182. {
  183. y -= stoll(two);
  184. }
  185. else
  186. {
  187. y -= mp[two];
  188. }
  189. }
  190. }
  191. mp[x] = y;
  192. }
  193. }
  194. }
  195.  
  196. int main()
  197. {
  198. Bustany;
  199. int t = 1;
  200. // cin >> t;
  201. while (t--)
  202. {
  203. solve();
  204. }
  205. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty