注意n,m在这里的意思,打印的时候要颠倒n,m!!!
#include <iostream>
#include <cstring>
using namespace std;
const int N = 110;
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
char g[N][N];
int st[N][N];
int n,m,q;
void dfs(int x,int y,char u){
g[x][y] = u;
st[x][y] = 1;
// cout << x << ' ' << y << ':' << endl;
for(int i = 0;i < 4;i++){
int tx = x + dx[i],ty = y + dy[i];
// cout << tx << ' ' << ty << ' ' << g[tx][ty] << endl;
if(tx >= 0 && tx < m && ty >= 0 && ty < n && !st[tx][ty]){
if(g[tx][ty] == '-' || g[tx][ty] == '|' || g[tx][ty] == '+') continue;
dfs(tx,ty,u);
}
}
}
int main(){
cin >> m >> n >> q;
for(int i = 0;i < m;i++)
for(int j = 0;j < n;j++)
g[i][j] = '.';
while(q--){
int op;
cin >> op;
if(!op){
int x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
if(x1 == x2){
char x = '|';
int ma_y = max(y1,y2),mi_y = min(y1,y2);
for(int i = mi_y;i <= ma_y;i++){
if(g[x1][i] == '-' || g[x1][i] == '+') g[x1][i] = '+';
else g[x1][i] = x;
}
}
else{
char x = '-';
int ma_x = max(x1,x2),mi_x = min(x1,x2);
for(int i = mi_x;i <= ma_x;i++){
if(g[i][y1] == '|' || g[i][y1] == '+') g[i][y1] = '+';
else g[i][y1] = x;
}
}
}else{
char u;
int x,y;
cin >> x >> y >> u;
memset(st,0,sizeof st);
dfs(x,y,u);
}
}
for(int i = n - 1;i >= 0;i--){
for(int j = 0;j < m;j++){
cout << g[j][i];
}
cout << endl;
}
return 0;
}