点击前往试题目录:https://blog.csdn.net/best335/article/details/99550556
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
typedef pair<int,int> P;
int main(){
int m,n,q;
char M[100][100],V[100][100],ch,F=char(1),T=char(0);
memset(M,0,sizeof(M));
cin>>m>>n>>q;
for(int i=0,c,x1,y1,x2,y2;i<q;++i){
cin>>c;
if(c==0){
cin>>x1>>y1>>x2>>y2;
if(x1==x2){
for(int y=min(y1,y2),ny=max(y1,y2)+1;y<ny;++y){
if(M[y][x1]!='+') M[y][x1]=M[y][x1]=='-'?'+':'|';
}
}
else{
for(int x=min(x1,x2),nx=max(x1,x2)+1;x<nx;++x)
if(M[y1][x]!='+') M[y1][x]=M[y1][x]=='|'?'+':'-';
}
}
else{
cin>>y1>>x1>>ch;
queue<P> q;
q.push(P(x1,y1));
for(int x=0;x<n;++x)
for(int y=0;y<m;++y)
V[x][y]=M[x][y]=='-'||M[x][y]=='|'||M[x][y]=='+'?F:T;
V[x1][y1]=F;
while(!q.empty()){
P p=q.front();q.pop();
int &x=p.first,&y=p.second,lx=x-1,rx=x+1,ly=y-1,ry=y+1;
M[x][y]=ch;
if(lx>-1&&V[lx][y]==T) V[lx][y]=F,q.push(P(lx,y));
if(rx<n&&V[rx][y]==T) V[rx][y]=F,q.push(P(rx,y));
if(ly>-1&&V[x][ly]==T) V[x][ly]=F,q.push(P(x,ly));
if(ry<m&&V[x][ry]==T) V[x][ry]=F,q.push(P(x,ry));
}
}
}
for(int i=n-1;i>-1;--i){
for(int j=0;j<m;++j)
cout<<(M[i][j]==T?'.':M[i][j]);
cout<<endl;
}
return 0;
}