题目描述
There is a square field of size n \times nn×n in which two cells are marked. These cells can be in the same row or column.
You are to mark two more cells so that they are the corners of a rectangle with sides parallel to the coordinate axes.
For example, if n=4n=4 and a rectangular field looks like this (there are asterisks in the marked cells):
\begin{matrix} .&.&*&.\\ .&.&.&.\\ *&.&.&.\\ .&.&.&.\\ \end{matrix}..∗.....∗.......
Then you can mark two more cells as follows
\begin{matrix} *&.&*&.\\ .&.&.&.\\ *&.&*&.\\ .&.&.&.\\ \end{matrix}∗.∗.....∗.∗.....
If there are several possible solutions, then print any of them.
输入格式
The first line contains a single integer tt ( 1 \le t \le 4001≤t≤400 ). Then tt test cases follow.
The first row of each test case contains a single integer nn ( 2 \le n \le 4002≤n≤400 ) — the number of rows and columns in the table.
The following nn lines each contain nn characters '.' or '*' denoting empty and marked cells, respectively.
It is guaranteed that the sums of nn for all test cases do not exceed 400400 .
It is guaranteed that there are exactly two asterisks on the field. They can be in the same row/column.
It is guaranteed that the solution exists.
输出格式
For each test case, output nn rows of nn characters — a field with four asterisks marked corresponding to the statements. If there multiple correct answers, print any of them.
题意翻译
一句话题意:给出 TT 个矩阵,每个矩阵由 NN 行 NN 列个 .
和 *
组成,保证矩阵中有且只有两个 *
,要求你再在矩阵上将两个 .
改成 *
使得 44 个 *
可以是一个矩阵的 44 个角(提示:两个 *
可能在同一行)。
输入输出样例
输入 #1复制
6 4 ..*. .... *... .... 2 *. .* 2 .* .* 3 *.* ... ... 5 ..... ..*.. ..... .*... ..... 4 .... .... *... *...
输出 #1复制
*.*. .... *.*. .... ** ** ** ** *.* *.* ... ..... .**.. ..... .**.. ..... .... .... **.. **..
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;//多组输入
while(t--)
{
int n;
cin>>n;
char c[n+1][n+1];
for(int i=1;i<=n;++i)
{
for(int j=1;j<=n;++j)
{
cin>>c[i][j];//一个n*n的矩阵 用来存*
}
}
//把每行每列的*用坐标(x1,y1)(x2,y2)来表示
int x1=-1,x2;//x1=-1作为一个标记
int y1,y2;
for(int i=1;i<=n;++i)
{
for(int j=1;j<=n;++j)
{
if(c[i][j]=='*')
{
if(x1==-1)//
{
x1=i;
y1=j;
}
else
{
x2=i;
y2=j;
break;//节省空间
}
}
}
}
//开始分组讨论
if(x1!=x2&&y1!=y2)
{
c[x1][y2] = c[x2][y1] = '*';
}
else if(x1==x2)//在同一行
{
if(x1==1)
{
c[2][y1]=c[2][y2]='*'; //就把第二行两列置称*
}
else
{
c[1][y1]=c[1][y2]='*';//否则的话 就把第一行两列置成*
}
}
else if(y1==1)//都在第一列
{
c[x1][2]=c[x2][2]='*'; //就把第二列两行置称*
}
else
{
c[x1][1]=c[x2][1]='*';//否则的话 就把第一列两行置成*
}
for(int i=1;i<=n;++i)
{
for(int j=1;j<=n;++j)
{
cout<<c[i][j];
}
cout<<endl;
}
}
return 0;
}