当前位置: 代码迷 >> C++ >> 不懂快要问。
  详细解决方案

不懂快要问。

热度:6175   发布时间:2013-02-26 00:00:00.0
不懂就要问。。。。
本帖最后由 immortal920812 于 2013-01-28 15:52:10 编辑
这是本人写的数独,但仍然有部分问题,在点A 弹出数独界面,点B 移动光标填入数字时,已经明确用switch语句禁止填入字母,但当我按d的时候他会把我整个数独界面全部改成9,请问这是为什么。。。。。

#include<iostream>
#include<stdio.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int array[9][9]= {0};

int Sudoku[9][9]={{0,1,4,0,5,0,0,0,3},
                  {6,0,0,0,0,9,4,2,0},
                  {8,0,0,1,0,0,0,9,0},
                  {0,0,5,0,9,0,0,4,0},
                  {4,0,0,7,0,8,0,5,2},
                  {0,7,0,0,2,0,6,0,0},
                  {0,9,0,0,0,1,0,0,5},
                  {0,2,8,3,0,0,0,0,4},
                  {5,0,0,0,6,0,7,1,0}};

int Su[9][9]={{0,1,4,0,5,0,0,0,3},
              {6,0,0,0,0,9,4,2,0},
              {8,0,0,1,0,0,0,9,0},
              {0,0,5,0,9,0,0,4,0},
              {4,0,0,7,0,8,0,5,2},
              {0,7,0,0,2,0,6,0,0},
              {0,9,0,0,0,1,0,0,5},
              {0,2,8,3,0,0,0,0,4},
              {5,0,0,0,6,0,7,1,0}};
int S[9][9];


int sudo[9][9];
enum
{
 ARROW_UP =256+72,
 ARROW_LEFT  =256+75,
 ARROW_DOWN  =256+80,
 ARROW_RIGHT =256+77,
 KEY_ESC =27
};
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

static int get_code(void)
{
int ch=getch();
if(ch == 0|| ch == 224)
ch= 256+getch();
return ch;
}
int isvalid(const int i, const int j)
{
 const int n = sudo[i][j];

 const static int query[] = {0, 0, 0, 3, 3, 3, 6, 6, 6};
 int t, u;
 
 for (t = 0; t < 9; t++)
  if (t != i && sudo[t][j] == n || t != j && sudo[i][t] == n)
   return 0;
  
  for (t = query[i]; t < query[i] + 3; t++)
   for (u = query[j]; u < query[j] + 3; u++)
    if ((t != i || u != j) && sudo[t][u] == n)
  相关解决方案