Advertisement
STANAANDREY

iTec 2k19 1

Oct 31st, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n, m;
  5. #define NMAX 55
  6. #define BACKSLASH '\\'
  7. #define SLASH '/'
  8. #define Point '.'
  9. ifstream fin("diamonds.in");
  10. ofstream fout("diamonds.out");
  11. char s[NMAX][NMAX];
  12. bool ver[NMAX][NMAX];
  13. vector < pair <int, int > > route;
  14.  
  15. inline bool isOk(int x, int y)
  16. {
  17.     int startX = x, startY = y;
  18.     while (true)
  19.     {
  20.         if (s[x][y] != SLASH)
  21.         {
  22.             return false;
  23.         }
  24.         if (s[x + 1][y] == BACKSLASH)
  25.         {
  26.             route.push_back(make_pair(x, y));
  27.             ver[x][y] = true;
  28.             break;
  29.         }
  30.         ver[x][y] = true;
  31.         route.push_back(make_pair(x, y));
  32.         x++;
  33.         y--;
  34.     }
  35.  
  36.     x++;
  37.     while (true)
  38.     {
  39.         if (s[x][y] != BACKSLASH)
  40.         {
  41.             return false;
  42.         }
  43.         if (s[x][y + 1] == SLASH)
  44.         {
  45.             route.push_back(make_pair(x, y));
  46.             ver[x][y] = true;
  47.             break;
  48.         }
  49.         ver[x][y] = true;
  50.         route.push_back(make_pair(x, y));
  51.         x++;
  52.         y++;
  53.     }
  54.  
  55.     y++;
  56.     while (true)
  57.     {
  58.         if (s[x][y] != SLASH)
  59.         {
  60.             return false;
  61.         }
  62.         if (s[x - 1][y] == BACKSLASH)
  63.         {
  64.             route.push_back(make_pair(x, y));
  65.             ver[x][y] = true;
  66.             break;
  67.         }
  68.         ver[x][y] = true;
  69.         route.push_back(make_pair(x, y));
  70.         x--;
  71.         y++;
  72.     }
  73.  
  74.     x--;
  75.     while (true)
  76.     {
  77.         if (s[x][y] != BACKSLASH)
  78.         {
  79.             return false;
  80.         }
  81.         if (x == startX && y == startY + 1)
  82.         {
  83.             route.push_back(make_pair(x, y));
  84.             ver[x][y] = true;
  85.             return true;
  86.         }
  87.         ver[x][y] = true;
  88.         route.push_back(make_pair(x, y));
  89.         x--;
  90.         y--;
  91.     }
  92.  
  93. }
  94.  
  95. inline void destroy_pattern()
  96. {
  97.     for (int i = 0; i < (int)route.size(); i++)
  98.     {
  99.         int x = route[i].first;
  100.         int y = route[i].second;
  101.         s[x][y] = Point;
  102.     }
  103.  
  104. }
  105.  
  106. int main()
  107. {
  108.     fin >> n >> m;
  109.     for (int i = 1; i <= n; i++)
  110.         fin >> (s[i] + 1);
  111.     bool ok;
  112.  
  113.     for (int i = 1; i <= n; i++)
  114.     {
  115.         for (int j = 1; j <= m; j++)
  116.         {
  117.             if (!ver[i][j])
  118.             {
  119.                 if (s[i][j] == SLASH)
  120.                     ok = isOk(i, j);
  121.                 else if (s[i][j] == BACKSLASH)
  122.                     s[i][j] = Point;
  123.                 if (!ok)
  124.                     destroy_pattern();
  125.                 ver[i][j] = true;
  126.             }
  127.             route.clear();
  128.         }
  129.     }//*/
  130.  
  131.     for (int i = 1; i <= n; i++)
  132.     {
  133.         for (int j = 1; j <= m; j++)
  134.             fout << s[i][j];
  135.         fout << '\n';
  136.     }
  137.  
  138.     return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement