Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. using namespace std;
  2. #include<iostream>
  3. #include<fstream>
  4.  
  5. int p, r, k, x, y;
  6. char mat[201][201], dirr;
  7. int nord, est, vest, sud;
  8.  
  9. int main() {
  10.  
  11. ifstream fin("robotel.in");
  12. ofstream fout("robotel.out");
  13.  
  14. fin >> p >> r >> k;
  15.  
  16. for (int i = 1; i<=r; i++) {
  17. for (int j = 1; j<=r; j++) {
  18. mat[i][j] = '^';
  19. }
  20. }
  21.  
  22. for (int i = 1; i<=k; i++) {
  23. fin >> x >> y >> dirr;
  24.  
  25. mat[x][y] = dirr;
  26. }
  27.  
  28. if (p == 1) {
  29. struct block {
  30. int l1;
  31. int c1;
  32. int l2;
  33. int c2;
  34. };
  35.  
  36. block b[k/2+1];
  37. int ind = 0;
  38. int lin1 = 0;
  39. int col1 = 0;
  40. int lin2 = 0;
  41. int col2 = 0;
  42.  
  43. for (int c = 1; c<=r; c++) {
  44. for (int l = 1; l<=r; l++) {
  45. if (mat[l][c] == 'S') {
  46. lin1 = l;
  47. col1 = c;
  48. } else if (mat[l][c] == 'N') {
  49.  
  50. if (lin1 != 0) {
  51. lin2 = l;
  52. col2 = c;
  53. ind++;
  54. b[ind] = {lin1, col1, lin2, col2};
  55. lin1 = 0;
  56. col1 = 0;
  57. lin2 = 0;
  58. col2 = 0;
  59. }
  60.  
  61. } else if (mat[l][c] == 'E' || mat[l][c] == 'V') {
  62. lin1 = 0;
  63. col1 = 0;
  64. }
  65. }
  66. lin1 = 0;
  67. col1 = 0;
  68. lin2 = 0;
  69. col2 = 0;
  70. }
  71. for (int l = 1; l<=r; l++) {
  72. for (int c = 1; c<=r; c++) {
  73. if (mat[l][c] == 'E') {
  74. lin1 = l;
  75. col1 = c;
  76. } else if (mat[l][c] == 'V') {
  77. if (lin1 != 0) {
  78. lin2 = l;
  79. col2 = c;
  80. ind++;
  81. b[ind] = {lin1, col1, lin2, col2};
  82. lin1 = 0;
  83. col1 = 0;
  84. lin2 = 0;
  85. col2 = 0;
  86. }
  87.  
  88. } else if (mat[l][c] == 'S' || mat[l][c] == 'N') {
  89. lin1 = 0;
  90. col1 = 0;
  91. }
  92. }
  93. lin1 = 0;
  94. col1 = 0;
  95. lin2 = 0;
  96. col2 = 0;
  97. }
  98. if (ind != 0) {
  99. for (int i = 1; i<ind; i++) {
  100. for (int j = i+1; j<=ind; j++) {
  101. if (b[i].l1 > b[j].l1) {
  102. swap (b[i], b[j]);
  103. } else if (b[i].l1 == b[j].l1) {
  104. if (b[i].c1 > b[j].c1) {
  105. swap (b[i], b[j]);
  106. }
  107. }
  108. }
  109. }
  110. for (int i = 1; i<=ind; i++) {
  111. fout << b[i].l1 << " " << b[i].c1 << " " << b[i].l2 << " " << b[i].c2 << endl;
  112. }
  113. } else {
  114. fout << "0";
  115. }
  116.  
  117. } else if (p == 2) {
  118.  
  119. bool schimb = false;
  120. bool ok = true;
  121. int lin = 1;
  122. int col = 1;
  123. char dirr = 'E';
  124. char ultsemn = ' ';
  125.  
  126. while (ok) {
  127. if (mat[lin][col] == '^' || schimb) {
  128. schimb = false;
  129. if (dirr == 'E') {
  130. if (++col > r) {
  131. ok = false;
  132. break;
  133. }
  134. est++;
  135. } else if (dirr == 'V') {
  136. if (--col < 1) {
  137. ok = false;
  138. break;
  139. }
  140. vest++;
  141. } else if (dirr == 'N') {
  142. if (--lin < 1) {
  143. ok = false;
  144. break;
  145. }
  146. nord++;
  147. } else if (dirr == 'S') {
  148. if (++lin > r) {
  149. ok = false;
  150. break;
  151. }
  152. sud++;
  153. }
  154. } else {
  155. if (mat[lin][col] == 'N') {
  156. if (ultsemn == 'S') {
  157. ok = false;
  158. } else {
  159. ultsemn = 'N';
  160. schimb = true;
  161. }
  162. } else if (mat[lin][col] == 'S') {
  163. if (ultsemn == 'N') {
  164. ok = false;
  165. } else {
  166. ultsemn = 'S';
  167. schimb = true;
  168. }
  169. } else if (mat[lin][col] == 'E') {
  170. if (ultsemn == 'V') {
  171. ok = false;
  172. } else {
  173. ultsemn = 'E';
  174. schimb = true;
  175. }
  176. } else if (mat[lin][col] == 'V') {
  177. if (ultsemn == 'E') {
  178. ok = false;
  179. } else {
  180. ultsemn = 'V';
  181. schimb = true;
  182. }
  183. }
  184. dirr = ultsemn;
  185. }
  186. }
  187. fout << nord << " " << est << " " << sud << " " << vest;
  188. }
  189.  
  190. fin.close();
  191. fout.close();
  192.  
  193. return 0;
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement