CodeForces-907#B 题解

正文

设数组 \(c_{x,y,i,j}\) 代表 \((x,y)\) 位置的大格子中 \((i,j)\) 位置的小格子。

很显然,输入中字符的输入顺序是要调整的,实际的顺序是 \(x,i,y,j\)

对于输入的 \(x_0,y_0\),只要对 3 取模(若整除则结果为 3)即可得到它对应的大格子的位置。

详见代码:

#include<iostream>
#define g(a) (a)%3==0?3:(a)%3//对3取模
using namespace std;
char c[4][4][4][4]; int x,y;
int main(){
  for(int x=1;x<=3;x++)
    for(int i=1;i<=3;i++)//输入
      for(int y=1;y<=3;y++)
        for(int j=1;j<=3;j++)
          cin>>c[x][y][i][j];
  cin>>x>>y; x=g(x),y=g(y);
  bool is_empty=true;//对应大方块是否为空
  for(int i=1;i<=3;i++)
    for(int j=1;j<=3;j++)
      if(c[x][y][i][j]=='.')
        is_empty=false,
        c[x][y][i][j]='!';
  if(is_empty)
    for(int x=1;x<=3;x++){
      for(int i=1;i<=3;i++){
        for(int y=1;y<=3;y++){
          for(int j=1;j<=3;j++)
            if(c[x][y][i][j]=='.')
              cout<<'!';
            else cout<<c[x][y][i][j];
          cout<<' ';}
        cout<<'\n';}
      cout<<'\n';}
  else
    for(int x=1;x<=3;x++){
      for(int i=1;i<=3;i++){
        for(int y=1;y<=3;y++){
          for(int j=1;j<=3;j++)
            cout<<c[x][y][i][j];
          cout<<' ';}
        cout<<'\n';}
      cout<<'\n';}
}

完结!!

后附

日志

v1.0 on 2023.01.18: 发布

posted @ 2023-01-24 17:12  IOIAK_wanguan  阅读(68)  评论(0)    收藏  举报