Guest User

main

a guest
Dec 27th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <stdio.h>
  4. #include "lib.c"
  5.  
  6. void draw(picture* matrix)
  7. {
  8. matrix->rows = max(matrix->rowsA, max(matrix->rowsB, matrix->rowsC));
  9. matrix->cols = max(matrix->colsA, max(matrix->colsB, matrix->colsC));
  10. printf("%d %d\n", matrix->rows, matrix->cols);
  11. for (int i = 0; i < matrix->rows; ++i)
  12. {
  13. for (int j = 0; j < matrix->cols; ++j)
  14. {
  15. char alph[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
  16. int mask = 15;
  17.  
  18. if (i < matrix->rowsC && j < matrix->colsC)
  19. {
  20. short first = matrix->C[i][j];
  21. int idx2 = first & mask;
  22. int idx1 = (first & (mask << 4)) >> 4;
  23. printf("%c%c", alph[idx1], alph[idx2]);
  24. }
  25. else
  26. {
  27. printf("00");
  28. }
  29.  
  30. if (i < matrix->rowsB && j < matrix->colsB)
  31. {
  32. short second = matrix->B[i][j];
  33. int idx2 = second & mask;
  34. int idx1 = (second & (mask << 4)) >> 4;
  35. printf("%c%c", alph[idx1], alph[idx2]);
  36. }
  37. else
  38. {
  39. printf("00");
  40. }
  41.  
  42. if (i < matrix->rowsA && j < matrix->colsA)
  43. {
  44. short third = matrix->A[i][j];
  45. int idx2 = third & mask;
  46. int idx1 = (third & (mask << 4)) >> 4;
  47. printf("%c%c", alph[idx1], alph[idx2]);
  48. }
  49. else
  50. {
  51. printf("00");
  52. }
  53. if (j != matrix->cols - 1)
  54. {
  55. printf(" ");
  56. }
  57. }
  58. printf("\n");
  59. }
  60. }
  61.  
  62. int main()
  63. {
  64. freopen("input.txt", "r", stdin);
  65. freopen("out.txt", "w", stdout);
  66. int n, m;
  67. scanf("%d %d", &n, &m);
  68. picture matrix;
  69. pictureInit(&matrix, n, m);
  70. for (int i = 0; i < n; ++i)
  71. {
  72. for (int j = 0; j < m; ++j)
  73. {
  74. int tmp;
  75. scanf("%x", &tmp);
  76. int mask = 255;
  77. matrix.A[i][j] = (tmp & mask);
  78. matrix.B[i][j] = (tmp & (mask << 8)) >> 8;
  79. matrix.C[i][j] = (tmp & (mask << 16)) >> 16;
  80. }
  81. }
  82. char field[4], command[10];
  83.  
  84. while (scanf("%s : %s :", field, command) != EOF)
  85. {
  86. if (!strcmp(command, "rotate"))
  87. {
  88. int angle;
  89. fscanf(stdin, "%d", &angle);
  90. rotate(&matrix, field[0], (angle / 90) % 4);
  91. rotate(&matrix, field[1], (angle / 90) % 4);
  92. rotate(&matrix, field[2], (angle / 90) % 4);
  93. }
  94. else if (!strcmp(command, "flip"))
  95. {
  96. char dir;
  97. fscanf(stdin, " %c", &dir);
  98. flip(&matrix, field[0], dir);
  99. flip(&matrix, field[1], dir);
  100. flip(&matrix, field[2], dir);
  101. }
  102. else if (!strcmp(command, "downscale"))
  103. {
  104. int rowsDown, colsDown;
  105. fscanf(stdin, "%d %d", &rowsDown, &colsDown);
  106. int flagA = 0; int flagDivA = 0;
  107. int flagB = 0; int flagDivB = 0;
  108. int flagC = 0; int flagDivC = 0;
  109.  
  110. if (field[0] == 'A') flagA = 1;
  111. if (field[0] == 'B' || field[1] == 'B') flagB = 1;
  112. if (field[0] == 'C' || field[1] == 'C' || field[2] == 'C') flagC = 1;
  113.  
  114. if (matrix.rowsA % rowsDown || matrix.colsA % colsDown) flagDivA = 1;
  115. if (matrix.rowsB % rowsDown || matrix.colsB % colsDown) flagDivB = 1;
  116. if (matrix.rowsC % rowsDown || matrix.colsC % colsDown) flagDivC = 1;
  117.  
  118. if (!(flagA & flagDivA) && !(flagB & flagDivB) && !(flagC & flagDivC))
  119. {
  120. downscale(&matrix, field[0], rowsDown, colsDown);
  121. downscale(&matrix, field[1], rowsDown, colsDown);
  122. downscale(&matrix, field[2], rowsDown, colsDown);
  123. }
  124. }
  125. else if (!strcmp(command, "upscale"))
  126. {
  127. int rowsUp, colsUp;
  128. fscanf(stdin, "%d %d", &rowsUp, &colsUp);
  129. int flagA = 0; int flagDivA = 0;
  130. int flagB = 0; int flagDivB = 0;
  131. int flagC = 0; int flagDivC = 0;
  132.  
  133. if (field[0] == 'A') flagA = 1;
  134. if (field[0] == 'B' || field[1] == 'B') flagB = 1;
  135. if (field[0] == 'C' || field[1] == 'C' || field[2] == 'C') flagC = 1;
  136.  
  137. if (matrix.rowsA * rowsUp > 1000 || matrix.colsA * colsUp > 1000) flagDivA = 1;
  138. if (matrix.rowsB * rowsUp > 1000 || matrix.colsB * colsUp > 1000) flagDivB = 1;
  139. if (matrix.rowsC * rowsUp > 1000 || matrix.colsB * colsUp > 1000) flagDivC = 1;
  140. if (!(flagA && flagDivA) && !(flagB && flagDivB) && !(flagC && flagDivC))
  141. {
  142. upscale(&matrix, field[0], rowsUp, colsUp);
  143. upscale(&matrix, field[1], rowsUp, colsUp);
  144. upscale(&matrix, field[2], rowsUp, colsUp);
  145. }
  146. }
  147. }
  148. //flip(&matrix,'B','H');
  149. draw(&matrix);
  150. picturePurge(&matrix, matrix.rows);
  151. return 0;
  152. }
Advertisement
Add Comment
Please, Sign In to add comment