fork download
  1. #include "pch.h"
  2. #include <io.h>
  3. #include <iostream>
  4. #include <conio.h>
  5. #include <stdio.h>
  6. #include <iomanip>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. int height(0), width(0), corner(0), direction(0), entryPoint(0);
  13. int number, numberAction;
  14. int n = 0;
  15. int key = 1;
  16. int code;
  17. int mas[12][12];
  18. int i, j;
  19.  
  20. for (i = 0; i < 11; i++)
  21. {
  22. for (j = 0; j < 11; j++)
  23. {
  24. mas[i][j] = 0;
  25. }
  26. }
  27. setlocale(0, "");
  28.  
  29. do
  30. {
  31. cout « "Введите количество строк" "\n";
  32. cin » width;
  33. cout « endl;
  34. } while ((width < 1) || (width > 12));
  35.  
  36. do
  37. {
  38. cout « "Введите количество столбцов" "\n";
  39. cin » height;
  40. cout « endl;
  41. } while ((height < 1) || (height > 12));
  42.  
  43. do
  44. {
  45. n = 0;
  46. system("cls");
  47. cout « "Спираль снаружи по часовой стрелке";
  48. if (key == 1) cout « "<==";
  49. cout « endl;
  50. cout « "Спираль снаружи против часовой стрелки";
  51. if (key == 2) cout « "<==";
  52. cout « endl;
  53. cout « "Спираль изнутри против часовой стрелки";
  54. if (key == 3) cout « "<==";
  55. cout « endl;
  56. cout « "Спираль изнутри по часовой стрелке ";
  57. if (key == 4) cout « "<==";
  58. cout « endl;
  59.  
  60. if (key == 1 || key == 2)
  61. {
  62. entryPoint = 1;
  63. }
  64. else if (key == 3 || key == 4)
  65. {
  66. entryPoint = 2;
  67. }
  68.  
  69. if (key == 1 || key == 3)
  70. {
  71. direction = 2;
  72. }
  73. else if (key == 2 || key == 4)
  74. {
  75. direction = 1;
  76. }
  77.  
  78. if (entryPoint == 1)
  79. {
  80. number = 1;
  81. numberAction = 1;
  82. }
  83. else {
  84. number = width * height;
  85. numberAction = -1;
  86. }
  87.  
  88. do
  89. {
  90. if (direction == 1)
  91. {
  92. for (int i = 0 + n; i < width - n; i++)
  93. {
  94. mas[i][n] = number;
  95. number += numberAction;
  96. }
  97. }
  98. else
  99. {
  100. for (int i = width - n - 1; i > -1 + n; i--)
  101. {
  102. mas[i][n] = number;
  103. number += numberAction;
  104. }
  105. }
  106.  
  107. if (number < width*height + 1 && number > 0) {
  108. for (int i = 1 + n; i < height - n; i++)
  109. {
  110. if (direction == 1) {
  111. mas[width - n - 1][i] = number;
  112. }
  113. else {
  114. mas[n][i] = number;
  115. }
  116. number += numberAction;
  117. }
  118. }
  119.  
  120. if (number < width*height + 1 && number > 0) {
  121. if (direction == 1)
  122. {
  123. for (int i = width - n - 2; i > 0 + n; i--)
  124. {
  125. mas[i][height - n - 1] = number;
  126. number += numberAction;
  127. }
  128. }
  129. else
  130. {
  131. for (int i = 1 + n; i < width - n - 1; i++)
  132. {
  133. mas[i][height - n - 1] = number;
  134. number += numberAction;
  135. }
  136. }
  137. }
  138.  
  139. if (number < width*height + 1 && number > 0) {
  140. for (int i = height - n - 1; i > 0 + n; i--)
  141. {
  142. if (direction == 1) {
  143. mas[n][i] = number;
  144. }
  145. else {
  146. mas[height - n - 1][i] = number;
  147. }
  148. number += numberAction;
  149. }
  150. }
  151. n++;
  152. } while (number < width*height + 1 && number > 0);
  153.  
  154. cout « endl;
  155.  
  156. for (int i = 0; i < width; i++)
  157. {
  158. for (int j = 0; j < height; j++)
  159. {
  160. printf("%4d", mas[i][j]);
  161. }
  162. cout « "\n";
  163. }
  164.  
  165. code = _getch();
  166. switch (code)
  167. {
  168. case 49:
  169. key = 1;
  170. break;
  171. case 50:
  172. key = 2;
  173. break;
  174. case 51:
  175. key = 3;
  176. break;
  177. case 52:
  178. key = 4;
  179. break;
  180. case 224:
  181. code = _getch();
  182. if (code == 72 && key > 1)
  183. {
  184. key--;
  185. }
  186. else if (code == 72 && key == 1)
  187. {
  188. key = 4;
  189. }
  190. else if (code == 80 && key < 4)
  191. {
  192. key++;
  193. }
  194. else if (code == 80 && key == 4)
  195. {
  196. key = 1;
  197. }
  198. break;
  199. default:
  200. break;
  201. }
  202. } while (code != 27);
  203.  
  204. return 0;
  205. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:10: fatal error: pch.h: No such file or directory
 #include "pch.h"
          ^~~~~~~
compilation terminated.
stdout
Standard output is empty