所有的评测用例满足:2 ≤ m, n ≤ 100,0 ≤ q ≤ 100,0 ≤ x < m(x表示输入数据中所有位置的x坐标),0 ≤ y < n(y表示输入数据中所有位置的y坐标)。
解题思路
本题在历年题目中属于比较简单的题目,需要注意的是,对于画线操作,遇到‘+’时不可修改。
main.cpp
#include<iostream>#include<string>#include<algorithm>
using namespace std;//Insert Charactervoidfillplant(string **plant,int m,int n,int x,int y,char temp){//Out Of Memoryif(y <0|| y >= n)return;if(x <0|| x >= m)return;if((*plant)[y][x]=='-'||(*plant)[y][x]=='|'||(*plant)[y][x]=='+'||(*plant)[y][x]== temp){return;}(*plant)[y][x]= temp;//Insert Aroundfillplant(plant, m, n, x -1, y, temp);fillplant(plant, m, n, x +1, y, temp);fillplant(plant, m, n, x, y -1, temp);fillplant(plant, m, n, x, y +1, temp);}intmain(){int m, n, q;int mod;int x1, y1, x2, y2;char temp;
string *plant;
cin >> m >> n >> q;getchar();
plant = new string [n];//Init '.'for(int i =0; i < n; i++){for(int j =0; j < m; j++){
plant[i]= plant[i]+'.';}}for(int i =0; i < q; i++){
cin >> mod;if(!mod){
cin >> x1 >> y1 >> x2 >> y2;getchar();if(x1 == x2){//y1!=y2for(int i =min(y1, y2); i <=max(y1, y2); i++){if(plant[i][x1]!='-'&& plant[i][x1]!='+')
plant[i][x1]='|';else
plant[i][x1]='+';}}elseif(y1 == y2){//x1!=x2for(int i =min(x1, x2); i <=max(x1, x2); i++){if(plant[y1][i]!='|'&& plant[y1][i]!='+')
plant[y1][i]='-';else
plant[y1][i]='+';}}}else{
cin >> x1 >> y1 >> temp;getchar();fillplant(&plant, m, n, x1, y1, temp);}}for(int i = n -1; i >=0; i--){//Reverse output
cout << plant[i]<< endl;}getchar();return0;}