当前位置: 首页>>代码示例>>C++>>正文


C++ Sudoku类代码示例

本文整理汇总了C++中Sudoku的典型用法代码示例。如果您正苦于以下问题:C++ Sudoku类的具体用法?C++ Sudoku怎么用?C++ Sudoku使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Sudoku类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(){
	Sudoku ss;
	ss.readIn();
	ss.transform();
	return 0;

}
开发者ID:shinshipower,项目名称:pd2-sudoku,代码行数:7,代码来源:transform.cpp

示例2: main

int main(){
    Sudoku *solvedPuzzle;
    //    int i = 0;
    //    int n = 0; //length
    //
    //
    std::string input;
    string t;
    for (int i = 0; i < 9; i++) {
        cin >> input;
        if (input.size()>10) {
            t = input;
            break;
        }
        t = t + input;
    }
    
    
    Sudoku puzzle = Sudoku(t);
    std::cout << "\n";
    std::cout << puzzle << endl;
    //    std::cout << "\n" << endl;
    puzzle.finalize();
    //    cout << "hi" << endl;            //test
    solvedPuzzle = solve (&puzzle);
    if (solvedPuzzle == NULL) {
        std:: cerr << "ERROR: nonSolvable puzzle" << endl;
    }
    else
        std::cout << *solvedPuzzle;
    return 0;
}
开发者ID:BingchengIT,项目名称:Suduko,代码行数:32,代码来源:main.cpp

示例3: while

bool Sudoku::solve()
{
  if(fin()){
    return true; 
  }
  while(1){
    Move m = findMove();
    if(m.val == 0){
      //no more moves
      return false;
    }
    Sudoku scopy = *this;
    bool result = scopy.applyMove(m);
    if(!result){
      cand[m.ii][m.jj][m.val] = false;
      continue;
    }
    result = scopy.solve();
    if(result){
      *this = scopy;
      return true;
    }else{
      cand[m.ii][m.jj][m.val] = false;
    }
  }
  return false;
}
开发者ID:desaic,项目名称:matchtex,代码行数:27,代码来源:Sudoku.cpp

示例4: solve

void RecursiveSolver::solve(Sudoku& sudoku) {
	this->_field = sudoku.getField();
	options = findMissing();
	
	for(map<int,vector<int>>::iterator it = options.begin(); it != options.end(); ++it) {
		cout << it->first << " " << ": ";
		for (vector<int>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
			cout << *it2 << ", ";
		}
		cout << endl;
	}
	map<int,vector<int>>::iterator it = options.begin();
	count = 0;
	
	int status = -1;
	do {
		status = guess(it->first);
		switch(status) {
		case RETURN_NEXT:
			it = std::next(it);
			break;
		case RETURN_PREV:
			it = std::prev(it);
			break;
		}
	} while(status != RETURN_EXIT);
	
	
	sudoku.setField(_field);
}
开发者ID:zenopax,项目名称:Sudoku,代码行数:30,代码来源:RecursiveSolver.cpp

示例5: main

int main(int argc, const char * argv[]) {
    
    Sudoku ss;
    ss.giveQuestion();
    
    return 0;
}
开发者ID:EvanChenPrograming,项目名称:pd2--sudoku,代码行数:7,代码来源:giveQuestion.cpp

示例6: temp

// smazani policka probiha tak, ze se zkopiruje cele sudoku az na pole, ktere mazeme. je to nutne kvuli obnove zakazanyvh poli v radcich/sloupcich/ctvercich
int Sudoku::smazat ( int x, int y )
{
  int u,v, smazano = false;
  if(!s.pole[y*9+x].zapsane || s.pole[y*9+x].pevne) // pokud na pozici nic neni nebo je tam pevne cislo, nic se nedeje
    return false;
  Sudoku temp (-1); // prazdne sudoku pro doplnovani
  // projdeme vse
  for (int i = 0;i < 81; i++)
  {
    // vynechavame pri kopirovani mazane policko
    if(i/9 == y && i%9 == x)
    {
      smazano = true;
      continue;
    }
    // nezapisujeme prazdna policka, doslo by k zaseknuti
    if (!s.pole[i].zapsane)
      continue;
    // doplnime zpet policko
    temp.doplnM (i%9, i/9, s.pole[i].zapsane);
    temp.s.pole[i].pevne = s.pole[i].pevne;
  }
  s = temp.s; // preneseni stavu do tohoto sudoku z docasneho
  return smazano;
}
开发者ID:peterix,项目名称:sudoku-solver,代码行数:26,代码来源:sudoku.cpp

示例7: main

int main()
{ 
	time_t start = time(NULL);
	
	std::string line;
	std::ifstream in;
	in.open("sudoku.txt");
	Sudoku x;
	int result = 0;
	for(int i = 0; i < 50; ++i)
	{
		getline(in,line);

		in >> x;
		Point p = x.getFirstEmpty();
		solve(x,p.i,p.j);
		
		std::cout << x << std::endl;
		result += getFirstThree(x);
	}

	std::cout << result << std::endl;
	printf("It took %d seconds\n", (time(NULL)-start));
	
}
开发者ID:esoros1,项目名称:Programming-Stuff,代码行数:25,代码来源:main.cpp

示例8: main

/**
 * Main method that gets initialized upon start of the program and creates an instance of the class Sudoku. A function
 * belonging to the Sudoku class is called that will generate a completely solved sudoku board and then the pointer to
 * the class is deleted to free up the allocated memory.
 */
int main() {
    Sudoku * mySudoku = new Sudoku();
    mySudoku->solve();
    delete mySudoku;

    return 0;
}
开发者ID:tonyzheng6,项目名称:Sudoku_Board_Solver,代码行数:12,代码来源:main.cpp

示例9: next

constexpr Cell next(const Sudoku& s)
{
  for(size_t i=0; i<s.dimension(); ++i)
    for(size_t j=0; j<s.dimension(); ++j)
      if (s(i,j) == 0) return {i,j};
  return {std::numeric_limits<Cell::first_type>::max(),std::numeric_limits<Cell::second_type>::max()};
}
开发者ID:valpo,项目名称:sudoku,代码行数:7,代码来源:main.cpp

示例10: main

int main()
{
	Sudoku ss;
	ss.ReadIn();
	ss.Solve();
	return 0;
}
开发者ID:jamex6554,项目名称:pd2-sudoku,代码行数:7,代码来源:solve.cpp

示例11: finished

constexpr bool finished(const Sudoku& s)
{
  for(size_t i=0; i<s.dimension(); ++i)
    for(size_t j=0; j<s.dimension(); ++j)
      if (s(i,j) == 0) return false;
  return true;
}
开发者ID:valpo,项目名称:sudoku,代码行数:7,代码来源:main.cpp

示例12: main

int main(){
	Sudoku ss;
	ss.readIn();
	ss.solve();

	return 0;
}
开发者ID:stbn199650,项目名称:pd2-sudoku,代码行数:7,代码来源:solve.cpp

示例13: assert

vector<PuzzleState*> Sudoku::getSuccessors() {
  assert(!isSolution()); // some move remains!

  vector<PuzzleState*> result;

  // find a blank square to fill in
  int row = 0;
  int col = 0;
  for (int i=0; i<9; i++) {
    for (int j=0; j<9; j++) {
      if (grid[i][j]==0) {
	row = i;
	col = j;
	// terminate the loop
	// no labelled breaks :(
	i = 9;
	j = 9;
      }
    }
  }

  for (int digit=1; digit<=9; digit++) {
    if (rowTally[row][digit]) continue; // digit already used in row
    if (colTally[col][digit]) continue; // digit already used in column
    if (zoneTally[row/3][col/3][digit]) continue; // digit already used in zone
    // This is a legal digit!  Add it to possible moves.
    Sudoku *temp = new Sudoku(*this);
    temp->applyMove(row,col,digit);
    result.push_back(temp);
  }

  return result;
}
开发者ID:asgard22,项目名称:cpsc_221,代码行数:33,代码来源:Sudoku.cpp

示例14: main

int main()
{
	Sudoku ss;
	int num;
	int i,j,k;
	int count = 0;
	while(cin >> num)
	{
		count++;
		if(count!=1 && ans_count != 0)
			cout << endl << endl;
		else if(count !=1)
			cout << endl;
		for(i=0; i<9; i++)
		{
			for(j=0; j<9; j++)
			{
				su[i][j] = 0;
				su3[i][j][0] = 0;
				ans[i][j] = 0;
				su2[i][j] = 0;
				for(k=1; k<10; k++)
				{
					su3[i][j][k] = 1;
				}
			}
		}
		have_zero = false;
		ans_count = 0;
		ss.readIn(num);
		ss.solve(num);
	}
}
开发者ID:bladeath860620,项目名称:ACM,代码行数:33,代码来源:UVA-989.cpp

示例15: sudokuTest

void sudokuTest() {
  vector< vector<int> > _grid = 
  {{3, 0, 6, 5, 0, 8, 4, 0, 0},
    {5, 2, 0, 0, 0, 0, 0, 0, 0},
    {0, 8, 7, 0, 0, 0, 0, 3, 1},
    {0, 0, 3, 0, 1, 0, 0, 8, 0},
    {9, 0, 0, 8, 6, 3, 0, 0, 5},
    {0, 5, 0, 0, 9, 0, 6, 0, 0},
    {1, 3, 0, 0, 0, 0, 2, 5, 0},
    {0, 0, 0, 0, 0, 0, 0, 7, 4},
    {0, 0, 5, 2, 0, 6, 3, 0, 0}};

  Sudoku* puzzle = new Sudoku( _grid );
  if(!puzzle->IsLegalBoard()) {
    drunkout("Illegal board.", cERROR);
  }
  puzzle->print();

  if(puzzle->solve())
    puzzle->print();
  else
    drunkout("No solution.", cINFO);

  delete puzzle;

}
开发者ID:madisodr,项目名称:Drunken-Algorithms,代码行数:26,代码来源:main.cpp


注:本文中的Sudoku类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。