diff --git a/Backtracking/cpp/N-Queen_Problem.cpp b/Backtracking/cpp/N-Queen_Problem.cpp new file mode 100644 index 00000000..54f5d8ef --- /dev/null +++ b/Backtracking/cpp/N-Queen_Problem.cpp @@ -0,0 +1,275 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef struct _CONSOLE_FONT_INFOEX +{ + ULONG cbSize; + DWORD nFont; + COORD dwFontSize; + UINT FontFamily; + UINT FontWeight; + WCHAR FaceName[LF_FACESIZE]; +}CONSOLE_FONT_INFOEX, *PCONSOLE_FONT_INFOEX; +#ifdef __cplusplus +extern "C" { +#endif +BOOL WINAPI SetCurrentConsoleFontEx(HANDLE hConsoleOutput, BOOL bMaximumWindow, PCONSOLE_FONT_INFOEX +lpConsoleCurrentFontEx); +#ifdef __cplusplus +} +#endif +int n; +//int** board=new int*[n]; +int board[15][15]; +void printboard() +{ + cout<Put the 1 such that\n\t->It does not repeat in same row and column.\n\t->and it also should not be repeated diagonally.\n"; + cout<<"->Game can be win if there is 1 in every row.\n"; + cout<<"Press enter to continue\n"; + cin.ignore(); + system("CLS"); + int level; + cout<<"SELECT LEVEL\n"; + cout<<"\n1.Easy\n2.Hard\n"; + cin>>level; + system("CLS"); + cout<<"\n "; + cfi.dwFontSize.X = 0; // Width of each character in the font +cfi.dwFontSize.Y = 200; // Height + SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi); + cout<=1;i--) + { + cout<<"\n\t"<>command; + + switch(command) + { + case 1: + { + + int rowno,columnno; + cout<<"enter the place number you want to put 1:\n"; + cout<<"\n enter in format rowno columnno\n"; + cin>>rowno>>columnno; + if(check(rowno-1,columnno-1)) + { + put(rowno-1,columnno-1); + + } + else + { + cout<<"you cannot put 1 here"; + Sleep(800); + } + break; + } + case 2: + { + int rowno,columnno; + cout<<"enter the place number you want to remove 1:\n"; + cout<<"\n enter in format rowno columnno\n"; + cin>>rowno>>columnno; + remove(rowno-1,columnno-1); + break; + } + case 3: + exit(0); + default: + cout<<"choose correct option\n"; + break; + } + system("CLS"); + } + printboard(); + cout<<"\nYOU WIN\n"; + cout<<"GAME OVER....."; +// for(int i=0;i