一道水题模拟题
思路
这道题可以用一个二维数组对于每个位置上的舒适度进行维护,并找出所有空位置上的舒适度最大的座位。最后将其他座位按原来的样子输出,舒适度最大的位置输出 即可。
代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
char p[7][9];
int x , y;
int a[7][9] =
{
{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0} ,
{0 , 3 , 3 , 0 , 4 , 4 , 0 , 3 , 3} ,
{0 , 3 , 3 , 0 , 4 , 4 , 0 , 3 , 3} ,
{0 , 2 , 2 , 0 , 3 , 3 , 0 , 2 , 2} ,
{0 , 2 , 2 , 0 , 3 , 3 , 0 , 2 , 2} ,
{0 , 1 , 1 , 0 , 2 , 2 , 0 , 1 , 1} ,
{0 , 1 , 1 , 0 , 2 , 2 , 0 , 1 , 1}
};
signed main()
{
for(int i = 1;i <= 6; ++ i)
for(int j = 1;j <= 8; ++ j)
{
cin >> p[i][j];
if(p[i][j] == '.')
if(a[i][j] > a[x][y])
{
x = i;
y = j;
}
}
for(int i = 1;i <= 6; ++ i)
{
for(int j = 1;j <= 8; ++ j)
if(x == i && y == j)
cout << 'P';
else
cout << p[i][j];
cout << '\n';
}
return 0;
}