import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Hi {
public static void main(String[] args) {
shuDu();
}
//原来的想法通过穷举法来计算出结果
public static void shuDu() {
List<Integer> exitNum=new ArrayList<>();
List<Integer> possable=new ArrayList<>();
Map<String,List<Integer>> map=new HashMap<>();
int [] arr= {1,2,3,4,5,6,7,8,9};
int [] minG= new int[10];
// int [] [] maxG= {minG,minG,minG,minG,minG,minG,minG,minG,minG,minG};
//已有数字的赋值,用10*10的二维数组,0索引不处理
//第一维横向,第二维纵向
int [] [] maxG= new int[10][10];
maxG[3][1]=8;maxG[7][1]=2;maxG[2][2]=3;maxG[4][2]=8;maxG[6][2]=2;
maxG[8][2]=6;maxG[1][3]=7;maxG[5][3]=9;maxG[9][3]=5;maxG[2][4]=5;
maxG[8][4]=1;maxG[3][5]=4;maxG[7][5]=6;maxG[2][6]=2;maxG[8][6]=7;
maxG[1][7]=4;maxG[5][7]=8;maxG[9][7]=6;maxG[2][8]=7;maxG[4][8]=1;
maxG[6][8]=3;maxG[8][8]=9;maxG[3][9]=1;maxG[7][9]=8;
System.out.println(maxG[1][3]);
//循环行
for(int i=1;i<maxG.length;i++) {
//循环列
for(int j=1;j<maxG[i].length;j++) {
//已经存在的值
exitNum=new ArrayList<>();
//可能填写的值
possable=new ArrayList<>();
if(maxG[i][j]==0) {
//循环9次
for(int k=1;k<10;k++) {
//第一横行
if(maxG[i][k]!=0) {
//存储存在的值
exitNum.add(new Integer(maxG[i][k]));
}
// 第一竖行
if(maxG[k][j]!=0) {
//存储存在的值
exitNum.add(new Integer(maxG[k][j]));
}
}
// 循环9个数字
for(int temp:arr){
if(!exitNum.contains(new Integer(temp))) {
// 添加可能填写的值
possable.add(new Integer(temp));
}
}
//左上第一个9宫格,横列
if(i<4) {
//左上第一个9宫格,数列
if(j<4) {
//当左上第一个9宫格满足条件,去除可能的值中的确定值
for(int k1=1;k1<4;k1++) {
for(int k2=1;k2<4;k2++) {
if(maxG[k1][k2]!=0) {
possable.remove(new Integer(maxG[k1][k2]));
}
}
}
}
// 上中9宫格
if(j>3&&j<7) {
//当上中9宫格满足条件,去除可能的值中的确定值
for(int k1=4;k1<7;k1++) {
for(int k2=4;k2<7;k2++) {
if(maxG[k1][k2]!=0) {
possable.remove(new Integer(maxG[k1][k2]));
}
}
}
}
//上右9宫格
if(j>6&&j<10) {
//当上右9宫格满足条件,去除可能的值中的确定值
for(int k1=7;k1<10;k1++) {
for(int k2=7;k2<10;k2++) {
if(maxG[k1][k2]!=0) {
possable.remove(new Integer(maxG[k1][k2]));
}
}
}
}
}
if(i>3&&i<7) {
//中左9宫格
if(j<4) {
//当中左9宫格满足条件,去除可能的值中的确定值
for(int k1=4;k1<7;k1++) {
for(int k2=1;k2<4;k2++) {
if(maxG[k1][k2]!=0) {
possable.remove(new Integer(maxG[k1][k2]));
}
}
}
}
//中中9宫格
if(j>3&&j<7) {
//当中中9宫格满足条件,去除可能的值中的确定值
for(int k1=4;k1<7;k1++) {
for(int k2=4;k2<7;k2++) {
if(maxG[k1][k2]!=0) {
possable.remove(new Integer(maxG[k1][k2]));
}
}
}
}
//中右9宫格
if(j>6&&j<10) {
//当中右9宫格满足条件,去除可能的值中的确定值
for(int k1=4;k1<7;k1++) {
for(int k2=7;k2<10;k2++) {
if(maxG[k1][k2]!=0) {
possable.remove(new Integer(maxG[k1][k2]));
}
}
}
}
}
if(i>6&&i<10) {
//下左9宫格
if(j<4) {
//当下左9宫格满足条件,去除可能的值中的确定值
for(int k1=7;k1<10;k1++) {
for(int k2=1;k2<4;k2++) {
if(maxG[k1][k2]!=0) {
possable.remove(new Integer(maxG[k1][k2]));
}
}
}
}
//下中9宫格
if(j>3&&j<7) {
//当下中9宫格满足条件,去除可能的值中的确定值
for(int k1=7;k1<10;k1++) {
for(int k2=4;k2<7;k2++) {
if(maxG[k1][k2]!=0) {
possable.remove(new Integer(maxG[k1][k2]));
}
}
}
}
//下右9宫格
if(j>6&&j<10) {
//当下右9宫格满足条件,去除可能的值中的确定值
for(int k1=7;k1<10;k1++) {
for(int k2=7;k2<10;k2++) {
if(maxG[k1][k2]!=0) {
possable.remove(new Integer(maxG[k1][k2]));
}
}
}
}
}
// 存储,多少行,多少列,的可以填写的满足所有条件的可能值
map.put(i+"-"+j,possable);
}
}
}
for(int i=1;i<maxG.length;i++) {
for(int j=1;j<maxG[i].length;j++) {
}
}
for(Map.Entry<String, List<Integer>> a: map.entrySet()) {
System.out.println(a.getKey());
for(Integer a1:a.getValue()) {
System.out.print(a1+"--");
}
System.out.println();
}
}
}