naquo

Little Quilt (doesn-t work)

Jul 13th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. //#pragma GCC optimize("Ofast")
  2. //#pragma GCC optimize("unroll-loops,no-stack-protector")
  3. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  4. #include <bits/stdc++.h>
  5.  
  6. #define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
  7. #define endl '\n'
  8. #define elif else if
  9. #define lli long long int
  10. #define ld long double
  11. #define vec vector
  12. #define forn(a) for(lli a=0; a<n; a++)
  13. #define all(x) x.begin(), x.end()
  14. #define presicion(x) cout<<fixed<<setprecision(x)
  15. #define dbg(x) cerr<<#x<<" = "<<x<<endl
  16. #define PI 3.14159265358979323
  17. #define sen(ang) sin((ang)*PI/180)
  18. //cout<<flush;
  19.  
  20. using namespace std;
  21.  
  22. class Drawing {
  23. protected:
  24. int rot;
  25. public:
  26. virtual int lines() = 0;
  27. virtual void draw(int line) = 0;
  28. virtual Drawing* turn() {
  29. rot = (rot + 1) % 4;
  30. return this;
  31. }
  32. void draw_all(void) {
  33. for (int i = 0; i < lines(); i++) {
  34. draw(i);
  35. cout << endl;
  36. }
  37. }
  38.  
  39. };
  40.  
  41. class A : public Drawing {
  42. public:
  43. int lines() override { return 2; }
  44.  
  45. void draw(int line) override {
  46. constexpr static char options[4][2][3] = {
  47. {"//", "/+"},
  48. {"\\\\", "+\\"},
  49. {"+/", "//"},
  50. {"\\+", "\\\\"}
  51. };
  52. cout << options[rot][line % 4];
  53. }
  54. };
  55.  
  56. class B : public Drawing {
  57. public:
  58. int lines() override { return 2; }
  59.  
  60. void draw(int line) override {
  61. constexpr static char options[4][2][3] = {
  62. {"--", "--"},
  63. {"||", "||"},
  64. {"--", "--"},
  65. {"||", "||"}
  66. };
  67. cout << options[rot][line % 4];
  68. }
  69. };
  70.  
  71.  
  72. class Sew : public Drawing {
  73. Drawing* a;
  74. Drawing* b;
  75. bool is_error;
  76. public:
  77. Sew(Drawing* _a, Drawing* _b) : a(_a), b(_b) {
  78. is_error = a->lines() != b->lines()
  79. || a->lines() == 1
  80. || b->lines() == 1;
  81. }
  82.  
  83. int lines() override {
  84. if (is_error)
  85. return 1;
  86. return rot % 2 ? a->lines() + b->lines() : a->lines();
  87. }
  88.  
  89. void draw(int line) override {
  90. if (is_error) {
  91. cout << "error";
  92. return;
  93. }
  94.  
  95. switch (rot) {
  96. case 0:
  97. a->draw(line);
  98. b->draw(line);
  99. break;
  100. case 1:
  101. if (line < a->lines())
  102. a->draw(line);
  103. else
  104. b->draw(line - a->lines());
  105. break;
  106. case 2:
  107. b->draw(line);
  108. a->draw(line);
  109. break;
  110. case 3:
  111. if (line < b->lines())
  112. b->draw(line);
  113. else
  114. a->draw(line - b->lines());
  115. break;
  116. }
  117. }
  118. Drawing* turn() override {
  119. rot = (rot + 1) % 4;
  120. a->turn();
  121. b->turn();
  122. return this;
  123. }
  124. };
  125.  
  126. Drawing* parse(string::iterator& por_ver) {
  127. Drawing* a;
  128. Drawing* b;
  129.  
  130. switch (*por_ver) {
  131. case 's':
  132. por_ver += 3;
  133. a = parse(por_ver);
  134. b = parse(por_ver);
  135. return new Sew(a, b);
  136. case 't':
  137. por_ver += 4;
  138. return parse(por_ver)->turn();
  139. case 'A':
  140. por_ver++;
  141. return new A();
  142. case 'B':
  143. por_ver++;
  144. return new B();
  145. default:
  146. return parse(++por_ver);
  147. }
  148. }
  149.  
  150. int main() {
  151. string expr;
  152. getline(cin, expr, ';');
  153. int i = 1;
  154. while (!cin.eof()) {
  155. auto it = expr.begin();
  156. cout << "Quilt " << i++ << ":" << endl;
  157. parse(it)->draw_all();
  158. getline(cin, expr, ';');
  159. }
  160. return 0;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment