fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7. //int cellTypes[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
  8.  
  9. int getCellType(int x, int y, const vector<vector<int>>& maze, int N) {
  10. int top = (y > 0 && maze[y - 1][x] == -1) ? 1 : 0;
  11. int bottom = (y < N - 1 && maze[y + 1][x] == -1) ? 1 : 0;
  12. int left = (x > 0 && maze[y][x - 1] == -1) ? 1 : 0;
  13. int right = (x < N - 1 && maze[y][x + 1] == -1) ? 1 : 0;
  14.  
  15. //int cellType = (top << 3) | (bottom << 2) | (left << 1) | right;
  16. int cellType = 0;
  17. if (left && !top && !bottom && !right) cellType = 1;
  18. else if (!left && top && !bottom && !right) cellType = 2;
  19. else if (left && top && !bottom && !right) cellType = 3;
  20. else if (!left && !top && !bottom && right) cellType = 4;
  21. else if (left && !top && !bottom && right) cellType = 5;
  22. else if (!left && top && !bottom && right) cellType = 6;
  23. else if (left && top && !bottom && right) cellType = 7;
  24. else if (!left && !top && bottom && !right) cellType = 8;
  25. else if (left && !top && bottom && !right) cellType = 9;
  26. else if (!left && top && bottom && !right) cellType = 10;
  27. else if (left && top && bottom && !right) cellType = 11;
  28. else if (!left && !top && bottom && right) cellType = 12;
  29. else if (left && !top && bottom && right) cellType = 13;
  30. else cellType = 14;
  31.  
  32. //int cellType = cellTypes[left + top * 2 + bottom * 4 + right * 8 - 1];
  33.  
  34. return cellType;
  35. }
  36.  
  37. int main() {
  38. int N;
  39. char comma;
  40.  
  41. cin >> N >> comma >> N;
  42.  
  43. vector<vector<int>> maze(N, vector<int>(N));
  44. string line;
  45.  
  46. cin.ignore();
  47. for (int i = 0; i < N; ++i) {
  48. getline(cin, line);
  49. stringstream ss(line);
  50. string cell;
  51. for (int j = 0; j < N; ++j) {
  52. getline(ss, cell, ',');
  53. maze[i][j] = stoi(cell);
  54. }
  55. }
  56.  
  57. for (int y = 0; y < N; ++y) {
  58. for (int x = 0; x < N; ++x) {
  59. if (maze[y][x] == 0) {
  60. int cellType = getCellType(x, y, maze, N);
  61. maze[y][x] = cellType;
  62. }
  63. }
  64. }
  65.  
  66. for (int i = 0; i < N; ++i) {
  67. for (int j = 0; j < N; ++j) {
  68. cout << maze[i][j];
  69. if (j != N - 1) cout << ",";
  70. }
  71. cout << endl;
  72. }
  73.  
  74. return 0;
  75. }
  76.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty