X is well known artist, no one knows the secrete behind the beautiful paintings of X except his friend Y, well the reason that Y knows X’s secrete is that he is that secret. Y is a programmer and he helps X with drawing paintings using computer program written by him. Unfortunately Y program is not working any more, now it’s your turn to help X by writing a program that helps him in painting, your program should accept a sequence of instructions, each will draw an opaque (filled) rectangle in the form: r1, c1, r2, c2, color. where (r1, c1) is the upper left corner of the rectangle and (r2, c2) is the lower right corner, and color is a character that denotes the color of this rectangle. all rectangles will be printed on a R by C plane, by default this plane is filled with dots (i.e. ‘.’). R and C between 1 and 100. for each instruction (1 ≤ ri ≤ R) and (1 ≤ ci ≤ C) and color is a ASCII character [a-z]. The number of instructions won’t exceed 100 instructions.
Input
The first line of input contains an integer T denotes number of test cases. The first line of each test case contains three integers R, C ,I where R and C denotes number of rows and columns of the painting, and I denotes number of instructions. Each of the next I lines contains four integers r1,c1,r2,c2 and the color character.
Output
Print the final plane after evaluating the instructions in order.
Example
Input
1
5 5 3
1 1 2 2 a
1 2 5 5 c
2 2 3 3 d
Output
acccc
addcc
.ddcc
.cccc
.cccc
题目
这题关键想说在字符串数组输出的时候,如果是多组数据,不要用WA的这种输出方式,ma数组的范围在多组数据输入过程中被改变。
/*WA*/
#include <bits/stdc++.h>
using namespace std;
char ma[110][110];
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int x,y,m;
scanf("%d%d%d",&x,&y,&m);
for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)
{
ma[i][j]='.';
}
}
int x1,x2,y1,y2;
char c;
for(int t=0;t<m;t++)
{
cin>>x1>>y1>>x2>>y2>>c;
for(int i=x1-1;i<x2;i++)
for(int j=y1-1;j<y2;j++)
ma[i][j]=c;
}
for(int i=0;i<x;i++)
{
cout<<ma[i]<<endl;
}
}
return 0;
}
样例输出
2
4 4 1
1 1 2 2 a 行列为4、4输出
aa..
aa..
....
....
2 2 1
1 1 1 2 b 行列为2、2输出
bb..
....
/*AC*/
#include <bits/stdc++.h>
using namespace std;
char ma[110][110];
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int x,y,m;
scanf("%d%d%d",&x,&y,&m);
for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)
{
ma[i][j]='.';
}
}
int x1,x2,y1,y2;
char c;
for(int t=0;t<m;t++)
{
cin>>x1>>y1>>x2>>y2>>c;
for(int i=x1-1;i<x2;i++)
for(int j=y1-1;j<y2;j++)
ma[i][j]=c;
}
for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)
cout<<ma[i][j];
cout<<endl;
}
}
return 0;
}