fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct point {
  5.  
  6. int abscissa, ordinate;
  7.  
  8. point() {
  9. abscissa = 0;
  10. ordinate = 0;
  11. }
  12.  
  13. point(int x, int y) {
  14. abscissa = x;
  15. ordinate = y;
  16. }
  17.  
  18. void setX(int x) {
  19. abscissa = x;
  20. }
  21.  
  22. void setY(int y) {
  23. ordinate = y;
  24. }
  25.  
  26. int getX() {
  27. return abscissa;
  28. }
  29.  
  30. int getY() {
  31. return ordinate;
  32. }
  33.  
  34. };
  35.  
  36. struct size {
  37.  
  38. int width, height;
  39.  
  40. size() {
  41. width = 0;
  42. height = 0;
  43. }
  44.  
  45. size(int w, int h) {
  46. width = w;
  47. height = h;
  48. }
  49.  
  50. int getWidth() {
  51. return width;
  52. }
  53.  
  54. int getHeight() {
  55. return height;
  56. }
  57.  
  58. };
  59.  
  60. struct screen {
  61.  
  62. size dimension; // dimension of the screen
  63. point cursor; // position of the cursor
  64. char **arr; // array that represents characters on the screen
  65.  
  66. // allocates the memory for the array and sets its dimension
  67. screen(size d) {
  68. dimension = d;
  69. arr = new char*[dimension.getWidth()];
  70. for(int i = 0; i < dimension.getWidth(); i++) {
  71. arr[i] = new char[dimension.getHeight()];
  72. }
  73. }
  74.  
  75. // deallocates the memory for the array
  76. void deallocate() {
  77. for(int i = 0; i < dimension.getWidth(); i++) {
  78. delete[] arr[i];
  79. }
  80. delete[] arr;
  81. }
  82.  
  83. // fills each cell by character c
  84. void fill(char c) {
  85. for(int i = 0; i < dimension.getWidth(); i++) {
  86. for(int j = 0; j < dimension.getHeight(); j++) {
  87. arr[i][j] = c;
  88. }
  89. }
  90. }
  91.  
  92. // print integer where cursor is located and returns position of the cursor
  93. point print(int i) {
  94. return print(to_string(i));
  95. }
  96.  
  97. // print string where cursor is located and returns position of the cursor
  98. point print(string s) {
  99. for(int i = 0; i < s.length(); i++) {
  100. arr[cursor.getX()][cursor.getY()] = s.at(i);
  101. moveCursor();
  102. }
  103. return cursor;
  104. }
  105.  
  106. // moves cursor to the right
  107. void moveCursor() {
  108. cursor.setX(cursor.getX() + 1 == dimension.getWidth() ? 0 : cursor.getX() + 1);
  109. cursor.setY(cursor.getX() == 0 ? cursor.getY() + 1 : cursor.getY());
  110. }
  111.  
  112.  
  113. // moves cursor to the point p
  114. void moveCursor(point p) {
  115. cursor.setX(p.getX());
  116. cursor.setY(p.getY());
  117. }
  118.  
  119. // returns char located at point p
  120. char getChar(point p) {
  121. return arr[p.getX()][p.getY()];
  122. }
  123.  
  124. // returns dimension of the screen
  125. size getSize() {
  126. return dimension;
  127. }
  128.  
  129. };
  130.  
  131. // returns length of integer
  132. int length(int number) {
  133. int result = 1;
  134. while((number /= 10) > 0) {
  135. result++;
  136. }
  137. return result;
  138. }
  139.  
  140. // returns sum of lengths of integers from from to to
  141. int length(int from, int to) {
  142. int result = 0;
  143. for(int i = from; i <= to; i++) {
  144. result += length(i);
  145. }
  146. return result;
  147. }
  148.  
  149. int main() {
  150. int n, m, k;
  151. cin >> n >> m >> k;
  152. screen screen(size(length(1, k), k + 1));
  153. screen.fill('+');
  154. for(int i = 1; i <= k; i++) {
  155. screen.print(i);
  156. }
  157. for(int i = 1; i <= k; i++) {
  158. screen.moveCursor(point(screen.getSize().getWidth() - length(i), i));
  159. screen.print(i);
  160. }
  161. for(int row = 0; row < m; row++) {
  162. for(int col = 0; col < n; col++) {
  163. cout << screen.getChar(point(col % screen.getSize().getWidth(), row % screen.getSize().getHeight()));
  164. }
  165. cout << endl;
  166. }
  167. screen.deallocate();
  168. return 0;
  169. }
Success #stdin #stdout 0s 3464KB
stdin
33 22 11
stdout
123456789101112345678910111234567
++++++++++++1++++++++++++1+++++++
++++++++++++2++++++++++++2+++++++
++++++++++++3++++++++++++3+++++++
++++++++++++4++++++++++++4+++++++
++++++++++++5++++++++++++5+++++++
++++++++++++6++++++++++++6+++++++
++++++++++++7++++++++++++7+++++++
++++++++++++8++++++++++++8+++++++
++++++++++++9++++++++++++9+++++++
+++++++++++10+++++++++++10+++++++
+++++++++++11+++++++++++11+++++++
123456789101112345678910111234567
++++++++++++1++++++++++++1+++++++
++++++++++++2++++++++++++2+++++++
++++++++++++3++++++++++++3+++++++
++++++++++++4++++++++++++4+++++++
++++++++++++5++++++++++++5+++++++
++++++++++++6++++++++++++6+++++++
++++++++++++7++++++++++++7+++++++
++++++++++++8++++++++++++8+++++++
++++++++++++9++++++++++++9+++++++