All pastes #339928 Raw Edit

Anonymous

public cpp v1 · immutable
·published 2007-02-04 12:21 UTC
rendered paste body
#include<iostream>/* Con ngua dien bat dau chay nha ---------------> go go */  const int size = 8;  void initialization();  void print();  void Knight ( int times, int row, int col );  bool K[size][size];  bool check( int row, int col);  int move_col[] = {-2, -1, +1, +2, +2, +1, -1, -2};  int move_row[] = {+1, +2, +2, +1, -1, -2, -2, -1};  int row, col, index, next_row, next_col;   int times;void initialization(){    index =0;    times = 0;    row = 0;    col = 0;       for ( int i=0; i < size; i++)    {        for ( int j=0; j < size; j++)        {            K[i][j] = false;        }    }  K[row][col] = true;}bool check ( int row, int col ){    if ( row > 7 || row < 0 || col > 7 || col < 0 || K[row][col] == true )        return false;    else        return true;}void print (){    index++;    cout << " Knight chay di nha' ^^: " << endl;    cout << " lan thu : " << index << endl;    for ( int k = 0; k < size; k++ )    {        for ( int m = 0; m < size; m++ )        {              if ( K[k][m] == true )              {                    cout << " C ";                             }                  else                   cout << " + ";        }    cout << endl;    }}void Knight ( int times, int row, int col){            if ( times == 1 )          print();      else      {              for ( int i = 0; i < 8; i++ )                {                  cout << " row = " << row << endl;                  cout << " col = " << col << endl;                                next_col = col + move_col[i];                  next_row = row + move_row[i];                                    cout << " -----row = " << next_row << endl;                  cout << " -----col = " << next_col << endl;                      if (check( next_row,next_col ))                  {                                            K[next_row][next_col] = true;                        Knight (times+1, next_row, next_col);                      K[next_row][next_col] = false;                  }                                }       }                 }                  void main(){   initialization();   Knight (0,0,0);int x;cin >> x;}