fork download
  1. #include <stdio.h>
  2. #define SIZE 50
  3.  
  4. int main() {
  5. int floor[SIZE][SIZE] = {0};
  6. int commands[] = {2, 5, 12, 3, 5, 12, 3, 5, 12, 3, 5, 12, 1, 6, 9};
  7. int commandIndex = 0;
  8. int penDown = 0;
  9. int direction = 0;
  10. int currentRow = 0;
  11. int currentCol = 0;
  12.  
  13. while (commands[commandIndex] != 9) {
  14. int command = commands[commandIndex];
  15.  
  16. if (command == 1) {
  17. penDown = 0;
  18. commandIndex++;
  19. } else if (command == 2) {
  20. penDown = 1;
  21. commandIndex++;
  22. } else if (command == 3) {
  23. direction = (direction + 1) % 4;
  24. commandIndex++;
  25. } else if (command == 4) {
  26. direction = (direction + 3) % 4;
  27. commandIndex++;
  28. } else if (command == 5) {
  29. commandIndex++;
  30. int spaces = commands[commandIndex];
  31.  
  32. for (int i = 0; i < spaces; i++) {
  33. if (penDown) {
  34. floor[currentRow][currentCol] = 1;
  35. }
  36.  
  37. if (direction == 0 && currentCol < SIZE - 1) {
  38. currentCol++;
  39. } else if (direction == 1 && currentRow < SIZE - 1) {
  40. currentRow++;
  41. } else if (direction == 2 && currentCol > 0) {
  42. currentCol--;
  43. } else if (direction == 3 && currentRow > 0) {
  44. currentRow--;
  45. }
  46. }
  47. if (penDown) {
  48. floor[currentRow][currentCol] = 1;
  49. }
  50. commandIndex++;
  51. } else if (command == 6) {
  52. for (int r = 0; r < SIZE; ++r) {
  53. for (int c = 0; c < SIZE; ++c) {
  54. if (floor[r][c] == 1) {
  55. printf("*");
  56. } else {
  57. printf(" ");
  58. }
  59. }
  60. printf("\n");
  61. }
  62. commandIndex++;
  63. }
  64. }
  65.  
  66. return 0;
  67. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
*************                                     
*           *                                     
*           *                                     
*           *                                     
*           *                                     
*           *                                     
*           *                                     
*           *                                     
*           *                                     
*           *                                     
*           *                                     
*           *                                     
*************