Codeforces Round #634 (Div. 3) D

D. Anti-Sudoku D. Anti-Sudoku

You are given a correct solution of the sudoku puzzle. If you don’t know what is the sudoku, you can read about it here.
The picture showing the correct sudoku solution:
在这里插入图片描述
Blocks are bordered with bold black color.
Your task is to change at most 9 elements of this field (i.e. choose some 1≤i,j≤9 and change the number at the position (i,j) to any other number in range [1;9]) to make it anti-sudoku. The anti-sudoku is the 9×9 field, in which:
Any number in this field is in range [1;9];
each row contains at least two equal elements;
each column contains at least two equal elements;
each 3×3 block (you can read what is the block in the link above) contains at least two equal elements.
It is guaranteed that the answer exists.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1≤t≤104) — the number of test cases. Then t test cases follow.

Each test case consists of 9 lines, each line consists of 9 characters from 1 to 9 without any whitespaces — the correct solution of the sudoku puzzle.

Output
For each test case, print the answer — the initial field with at most 9 changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.

//题目意思大概就是至少改变9个方格,造成数独的每一列每一行都有重复的元素
//同时9个小方块中也要有重复的
//画图就可以了
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<string>
#define ll long long
using namespace std;
string str="abcdefghijklmnopqrstuvwxyz";
char p[13]={'0','2','3','4','5','6','7','8','9','1'};
char mapp[12][12];
int main(){
    int T;
    cin>>T;
	while(T--)
    {
       int k=1;
       getchar();
       for(int i=1;i<=9;i++)
       for(int j=1;j<=9;j++){
       	cin>>mapp[i][j];
	   }
       for(int i=1;i<=3;i++)
       {
       	mapp[i][k]=p[(int)(mapp[i][k]-'0')];
       	k=k+3;
	   }
	   k=2;
	   for(int i=4;i<=6;i++)
       {
       	mapp[i][k]=p[(int)(mapp[i][k]-'0')];
       	k=k+3;
	   }
	   k=3;
	   for(int i=7;i<=9;i++)
       {
       	mapp[i][k]=p[(int)(mapp[i][k]-'0')];
       	k=k+3;
	   }
	   for(int i=1;i<=9;i++){
	   	for(int j=1;j<=9;j++)
	   	{
	   		cout<<mapp[i][j];
		}
		cout<<endl;
	   }
	}
	return 0;
} 
发布了23 篇原创文章 · 获赞 0 · 访问量 368

猜你喜欢

转载自blog.csdn.net/qq_43328587/article/details/105517463