画图
#include<cstdio> #include<iostream> #include<algorithm> #include<vector> #include<string> #include<queue> #include<map> using namespace std; char mp[105][105]; int n,m; void dfs(int x,int y,char ch) //谨记 x是原数组的列数,y是行数 { if(x<0 || x>=n || y<0 || y>=m) return; if(mp[x][y]=='+' || mp[x][y]=='|' || mp[x][y]=='-' || mp[x][y]==ch) return; mp[x][y] = ch; dfs(x+1,y,ch); dfs(x-1,y,ch); dfs(x,y+1,ch); dfs(x,y-1,ch); } int main() { //本题注意点: x是列数,y是行数但需要转换一下坐标 int q; cin>>m>>n>>q; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { mp[i][j] = '.'; } } for(int i=0;i<q;i++) { int type; cin>>type; if(type == 0) { int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; //坐标转换 ,x对应于原数组中列数,(n-1-y)对应于原数组的行数(由上往下数) y1 = n-1-y1; y2 = n-1-y2; if(x1 == x2) { if(y1 > y2) { int t; t = y1; y1 = y2; y2 = t; } //cout<<y1<<" "<<y2<<endl; for(int j=y1;j<=y2;j++) { if(mp[j][x1] == '.') mp[j][x1] = '|'; else if(mp[j][x1] == '-') mp[j][x1] = '+'; else if(mp[j][x1] == '+') continue; else mp[j][x1] = '|'; } } else if(y1==y2) { if(x1 > x2) { int t; t = x1; x1 = x2; x2 = t; } //cout<<x1<<" "<<x2<<endl; for(int j=x1;j<=x2;j++) { if(mp[y1][j] == '.') mp[y1][j] = '-'; else if(mp[y1][j] == '|') mp[y1][j] = '+'; else if(mp[y1][j] == '+') continue; else mp[y1][j] = '-'; } } } else { int x1,y1; char ch; cin>>x1>>y1>>ch; y1 = n-1-y1; dfs(y1,x1,ch);//谨记 x是原数组的列数,y是行数 } /* for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { cout<<mp[i][j]; } cout<<endl; }*/ } for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { cout<<mp[i][j]; } cout<<endl; } return 0; }