A -- chess play
Bob has a n×mn×m chessboard, which has two kinds of chess pieces.one is black, and the other is white.
As for chessboard, you can do three operations:
- 1 1 x y1 1 x y (means add a white chess piece to position (x, y))
- 1 2 x y1 2 x y(means add a black chess piece to position (x, y))
- 2 x1 x22 x1 x2(means swap the x1x1 row and x2x2 row)
(note: if you add one new chess to a position where there already is a chess, you need throw the old chess away firstly.)
In the initial time the chessboard is empty, and your mission is to show the final chessboard.
Please look at the example for more details.
INPUT
There are multiple test cases.The first line is a number T (
T ≤10T ≤10), which means the number of cases.For each case, the first line contains three integers n, m and q
(1≤n,m≤103,1≤q≤106)(1≤n,m≤103,1≤q≤106). Then follow
qq lines are the operations.As for each operation,
1≤xi,yi≤n1≤xi,yi≤n
OUTPUT
Print n lines which containing m characters - the final chessboard.
SAMPLE INPUT
2
2 2 2
1 1 1 1
2 1 2
4 3 4
1 1 1 1
2 1 2
1 2 1 1
2 2 3
SAMPLE OUTPUT
..
w.
b..
...
w..
...
题意:交换矩阵的行
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char map[1010][1010];
int a[1010];
int main()
{
int n,m,q;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&q);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
map[i][j] = '.';
}
for(int i = 1 ; i <= n ; i++)
a[i] = i;
while(q--)
{
int d,e,x,y;
scanf("%d",&d);
if(d == 1)
{
scanf("%d%d%d",&e,&x,&y);
if(e == 1)
map[a[x]][y] = 'w';
else
map[a[x]][y] = 'b';
}
else
{
scanf("%d%d",&x,&y);
swap(a[x],a[y]);
}
}
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++){
printf("%c",map[a[i]][j]);
if(j == m)
printf("\n");
}
}
return 0;
}