Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int chess[10][10],row,col,cnt=0;
- bool check(int ro,int column)
- {
- for(int i=0;i<8;i++){
- if(chess[i][column])
- return false;
- }
- for(int j=0;j<8;j++)
- {
- if(chess[ro][j])
- return false;
- }
- for(int i=0;i<8;i++)
- {
- for(int j=0;j<8;j++)
- {
- if(chess[i][j] && abs(ro-i)==abs(column-j))
- return false;
- }
- }
- return true;
- }
- void queen(int queencnt,int column)
- {
- if(queencnt==0 && column==8 && chess[row][col]==1)
- {
- cnt++;
- printf("%2d ",cnt);//6ta space
- for(int i=0;i<8;i++)
- {
- for(int j=0;j<8;j++)
- {
- if(chess[j][i]==1 && i==0)
- printf("%d",j+1);
- else if(chess[j][i]==1)
- printf(" %d",j+1);
- }
- }
- cout<<endl;
- }
- for(int x=0;x<8;x++)
- {
- if(check(x,column)==true)
- {
- chess[x][column]=1;
- queen(queencnt-1,column+1);
- chess[x][column]=0;
- }
- }
- }
- int main()
- {
- int t,cas,i,j,k;
- cin>>t;
- for(cas=1;cas<=t;cas++)
- {
- cin>>row>>col;
- row--,col--;
- cnt=0;
- memset(chess,0,sizeof(chess));
- printf("SOLN COLUMN\n");//7ta space;
- printf(" # 1 2 3 4 5 6 7 8\n\n");//prothome 1 ta pore 8ta
- queen(8,0);
- if(cas!=t)
- cout<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement