fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define file(NAME) if (fopen(NAME".inp", "r")) freopen(NAME".inp", "r", stdin), freopen(NAME".out", "w", stdout);
  5. #define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
  6. #define int long long
  7. #define pb push_back
  8. #define fi first
  9. #define se second
  10. #define pii pair<int, int>
  11.  
  12.  
  13.  
  14. string s;
  15. bool fi = 0, fj = 0;
  16. int daui[5], dauj[5];
  17. int li = -1, ri = -1;
  18. int lj = -1, rj = -1;
  19. vector<int> arr_i, arr_j;
  20.  
  21.  
  22.  
  23.  
  24. void preparefi() {
  25. string so = "";
  26. int type = 0;
  27. for (char ch : s) {
  28. if (ch == '+') {
  29. type = 1;
  30. continue;
  31. }
  32.  
  33. if (ch == '-') {
  34. type = 2;
  35. continue;
  36. }
  37.  
  38.  
  39. if (ch == '*') {
  40. type = 3;
  41. continue;
  42. }
  43.  
  44.  
  45.  
  46. if (isdigit(ch)) so += ch;
  47. }
  48.  
  49. if (so.empty()) so += '0';
  50. daui[type] = stoll(so);
  51. }
  52.  
  53.  
  54.  
  55.  
  56.  
  57. void preparefj() {
  58. string so = "";
  59. int type = 0;
  60. for (char ch : s) {
  61. if (ch == '+') {
  62. type = 1;
  63. continue;
  64. }
  65.  
  66. if (ch == '-') {
  67. type = 2;
  68. continue;
  69. }
  70.  
  71.  
  72. if (ch == '*') {
  73. type = 3;
  74. continue;
  75. }
  76.  
  77.  
  78.  
  79. if (isdigit(ch)) so += ch;
  80. }
  81.  
  82. if (so.empty()) so += '0';
  83. dauj[type] = stoll(so);
  84. }
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. void prepare_arr_i() {
  92. string so = "";
  93.  
  94. int dauphay = 0, daucham = 0;
  95. for (char ch : s) {
  96. if (isdigit(ch)) so += ch;
  97.  
  98. if (ch == '.' || daucham == 1) {
  99. if (so.empty()) {
  100. daucham = 1;
  101. continue;
  102. }
  103.  
  104. if (li == -1) {
  105. li = stoll(so);
  106. so = "";
  107.  
  108. }
  109.  
  110.  
  111. if (so.size() && ch == ']' && li != -1) {
  112. ri = stoll(so);
  113. so = "";
  114.  
  115. }
  116.  
  117.  
  118. }
  119.  
  120.  
  121.  
  122.  
  123. if (ch == ',' || dauphay == 1) {
  124. dauphay = 1;
  125.  
  126. if (so.empty()) {
  127. continue;
  128. }
  129.  
  130. if (ch == ',' || ch == ']') {
  131. arr_i.pb(stoll(so));
  132. so = "";
  133. }
  134.  
  135. }
  136. }
  137. }
  138.  
  139.  
  140.  
  141.  
  142.  
  143. void prepare_arr_j() {
  144. string so = "";
  145.  
  146. int dauphay = 0, daucham = 0;
  147. for (char ch : s) {
  148. if (isdigit(ch)) so += ch;
  149.  
  150. if (ch == '.' || daucham == 1) {
  151. daucham = 1;
  152.  
  153. if (so.empty()) {
  154. continue;
  155. }
  156.  
  157. if (lj == -1) {
  158. lj = stoll(so);
  159. so = "";
  160.  
  161. }
  162.  
  163.  
  164. if (so.size() && ch == ']' && lj != -1) {
  165. rj = stoll(so);
  166. so = "";
  167. }
  168.  
  169.  
  170. }
  171.  
  172.  
  173.  
  174.  
  175. if (ch == ',' || dauphay == 1) {
  176. dauphay = 1;
  177.  
  178. if (so.empty()) {
  179. continue;
  180. }
  181.  
  182. if (ch == ',' || ch == ']') {
  183. arr_j.pb(stoll(so));
  184. so = "";
  185. }
  186.  
  187. }
  188. }
  189. }
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198. void solve() {
  199. int dauchami = 0, dauphayi = 0, dauchamj = 0, dauphayj = 0;
  200.  
  201.  
  202. if (li != -1 && ri != -1) dauchami = 1;
  203. else dauphayi = 1;
  204.  
  205. if (lj != -1 && rj != -1) dauchamj = 1;
  206. else dauphayj = 1;
  207.  
  208.  
  209.  
  210.  
  211.  
  212. cout << '[';
  213.  
  214.  
  215. if (dauchami == 1) {
  216. FOR(i, li, ri) {
  217. int ans1 = i;
  218.  
  219. ans1 += daui[1];
  220. ans1 -= daui[2];
  221. ans1 *= daui[3];
  222.  
  223. if (dauchamj == 1) {
  224. FOR(j, lj, rj) {
  225. int ans2 = j;
  226.  
  227. ans2 += dauj[1];
  228. ans2 -= dauj[2];
  229. ans2 *= dauj[3];
  230.  
  231.  
  232. cout << '(' << ans1 << ", " << ans2 << ")";
  233. if (i != ri || j != rj) cout << ", ";
  234.  
  235. }
  236. }
  237. else {
  238. for (int j = 0; j < arr_j.size(); ++j) {
  239. int& ans2 = arr_j[j];
  240.  
  241. ans2 += dauj[1];
  242. ans2 -= dauj[2];
  243. ans2 *= dauj[3];
  244.  
  245. cout << '(' << ans1 << ", " << ans2 << ")";
  246. if (i != ri || j != arr_j.size() - 1) cout << ", ";
  247. }
  248. }
  249. }
  250. }
  251. else {
  252. for (int i = 0; i < arr_i.size(); ++i) {
  253. int ans1 = arr_i[i];
  254.  
  255. ans1 += daui[1];
  256. ans1 -= daui[2];
  257. ans1 *= daui[3];
  258.  
  259. if (dauchamj == 1) {
  260. FOR(j, lj, rj) {
  261. int ans2 = j;
  262.  
  263. ans2 += dauj[1];
  264. ans2 -= dauj[2];
  265. ans2 *= dauj[3];
  266.  
  267.  
  268. cout << '(' << ans1 << ", " << ans2 << ")";
  269. if ((i != arr_i.size() - 1) || j != rj) cout << ", ";
  270.  
  271. }
  272. }
  273. else {
  274. for (int j = 0; j < arr_j.size(); ++j) {
  275. int& ans2 = arr_j[j];
  276.  
  277. ans2 += dauj[1];
  278. ans2 -= dauj[2];
  279. ans2 *= dauj[3];
  280.  
  281. cout << '(' << ans1 << ", " << ans2 << ")";
  282. if ((i != arr_i.size() - 1) || j != arr_j.size() - 1) cout << ", ";
  283. }
  284. }
  285. }
  286. }
  287.  
  288.  
  289. cout << ']';
  290. }
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297. signed main() {
  298. ios::sync_with_stdio(0);
  299. cin.tie(0); cout.tie(0);
  300.  
  301.  
  302.  
  303.  
  304. daui[1] = 0, daui[2] = 0, daui[3] = 1;
  305. dauj[1] = 0, dauj[2] = 0, dauj[3] = 1;
  306.  
  307.  
  308. int cnt = 0;
  309.  
  310. while (cin >> s) {
  311. ++cnt;
  312.  
  313. if (!fi) {
  314. preparefi();
  315. fi = 1;
  316. continue;
  317. }
  318.  
  319.  
  320. if (!fj) {
  321. preparefj();
  322. fj = 1;
  323. continue;
  324. }
  325.  
  326.  
  327. if (cnt == 6) prepare_arr_i();
  328. if (cnt == 9) prepare_arr_j();
  329. }
  330.  
  331.  
  332.  
  333. solve();
  334.  
  335.  
  336. return 0;
  337. }
Success #stdin #stdout 0.01s 5288KB
stdin
[(i+10, j+5) | i <- [3,4], j <- [5,6,50]]
stdout
[(13, 10), (13, 11), (13, 55), (14, 15), (14, 16), (14, 60)]