Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n, m;
- #define NMAX 55
- #define BACKSLASH '\\'
- #define SLASH '/'
- #define Point '.'
- ifstream fin("diamonds.in");
- ofstream fout("diamonds.out");
- char s[NMAX][NMAX];
- bool ver[NMAX][NMAX];
- vector < pair <int, int > > route;
- inline bool isOk(int x, int y)
- {
- int startX = x, startY = y;
- while (true)
- {
- if (s[x][y] != SLASH)
- {
- return false;
- }
- if (s[x + 1][y] == BACKSLASH)
- {
- route.push_back(make_pair(x, y));
- ver[x][y] = true;
- break;
- }
- ver[x][y] = true;
- route.push_back(make_pair(x, y));
- x++;
- y--;
- }
- x++;
- while (true)
- {
- if (s[x][y] != BACKSLASH)
- {
- return false;
- }
- if (s[x][y + 1] == SLASH)
- {
- route.push_back(make_pair(x, y));
- ver[x][y] = true;
- break;
- }
- ver[x][y] = true;
- route.push_back(make_pair(x, y));
- x++;
- y++;
- }
- y++;
- while (true)
- {
- if (s[x][y] != SLASH)
- {
- return false;
- }
- if (s[x - 1][y] == BACKSLASH)
- {
- route.push_back(make_pair(x, y));
- ver[x][y] = true;
- break;
- }
- ver[x][y] = true;
- route.push_back(make_pair(x, y));
- x--;
- y++;
- }
- x--;
- while (true)
- {
- if (s[x][y] != BACKSLASH)
- {
- return false;
- }
- if (x == startX && y == startY + 1)
- {
- route.push_back(make_pair(x, y));
- ver[x][y] = true;
- return true;
- }
- ver[x][y] = true;
- route.push_back(make_pair(x, y));
- x--;
- y--;
- }
- }
- inline void destroy_pattern()
- {
- for (int i = 0; i < (int)route.size(); i++)
- {
- int x = route[i].first;
- int y = route[i].second;
- s[x][y] = Point;
- }
- }
- int main()
- {
- fin >> n >> m;
- for (int i = 1; i <= n; i++)
- fin >> (s[i] + 1);
- bool ok;
- for (int i = 1; i <= n; i++)
- {
- for (int j = 1; j <= m; j++)
- {
- if (!ver[i][j])
- {
- if (s[i][j] == SLASH)
- ok = isOk(i, j);
- else if (s[i][j] == BACKSLASH)
- s[i][j] = Point;
- if (!ok)
- destroy_pattern();
- ver[i][j] = true;
- }
- route.clear();
- }
- }//*/
- for (int i = 1; i <= n; i++)
- {
- for (int j = 1; j <= m; j++)
- fout << s[i][j];
- fout << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement