题意:
思路:
将给的坐标把它转化为左上角(0,0)的形式进行操作。此时‘-’ 与 ‘|’ 也要变化。之后再把处理完的矩阵按照逆时针旋转90度输出即可。
代码:
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<cstring>
#include<set>
#include<cmath>
#include<queue>
#include<algorithm>
#define rep(i,j,k) for(int i=j;i<k;++i)
#define mst(a,b) memset((a),(b),sizeof(a))
#include<cstring>
using namespace std;
typedef long long LL;
typedef vector<int, int> pii;
int n, m;
int dir[4][2] = { -1,0,0,1,1,0,0,-1 };
char a[105][105];
bool ok(int x, int y) {
if (x < 0 || x >= n) return false;
if (y < 0 || y >= m) return false;
if (a[x][y] == '-' || a[x][y] == '|' || a[x][y] == '+') return false;
return true;
}
void dfs(int x, int y, char c) {
for (int i = 0; i < 4; ++i) {
int nx = x + dir[i][0];
int ny = y + dir[i][1];
if (ok(nx, ny) && a[nx][ny] != c) {
a[nx][ny] = c;
dfs(nx, ny, c);
}
}
}
int sp(int& x, int& y) {
int t = x; x = y; y = t;
}
int main()
{
//freopen("input.txt","r",stdin);
ios::sync_with_stdio(false);
cin.tie(nullptr);
// n 为 此图中的行 为转换后的列 m为列为 转换后的行
int q, tp, x1, y1, x2, y2;
char c;
cin >> n >> m >> q;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) a[i][j] = '.';
}
while (q--) {
cin >> tp;
if (tp == 1) {
cin >> x1 >> y1 >> c;
a[x1][y1] = c;
dfs(x1, y1, c);
}
else if (tp == 0) {
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == x2) {
if (y1 > y2) sp(y1, y2);
rep(j, y1, y2 + 1) {
if (a[x1][j] == '-' || a[x1][j] == '+') a[x1][j] = '+';//这里不能含有'|',下面同理
else
a[x1][j] = '|';
}
}
else if (y1 == y2) {
if (x1 > x2) sp(x1, x2);
rep(i, x1, x2 + 1) {
if (a[i][y1] == '|' || a[i][y1] == '+') a[i][y1] = '+';
else a[i][y1] = '-';
}
}
}
}
// 逆时针旋转90度输出
for (int j = m - 1; j >= 0; --j) {
for (int i = 0; i < n; ++i) {
cout << a[i][j];
}
cout << endl;
}
return 0;
}