Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<graphics.h>
- #include<stdio.h>
- #include<conio.h>
- int check(int,int,int,int);
- void drawqueen(int,int);
- void main() {
- int i,j,k,l,m,n,p,q,c=0;
- char s[50];
- int gd=DETECT,gm;
- initgraph(&gd,&gm,"c:\\tc\\bgi");
- for(i=0;i<8;++i) {
- for(j=0;j<8;++j) {
- if(!check(0,i,1,j)) continue;
- else
- for(k=0;k<8;++k) {
- if(!check(0,i,2,k) || !check(1,j,2,k))continue;
- else
- for(l=0;l<8;++l) {
- if(!check(0,i,3,l) || !check(1,j,3,l) || !check(2,k,3,l))continue;
- else
- for(m=0;m<8;++m) {
- if(!check(0,i,4,m) || !check(1,j,4,m) || !check(2,k,4,m) || !check(3,l,4,m))continue;
- else
- for(n=0;n<8;++n) {
- if(!check(0,i,5,n) || !check(1,j,5,n) || !check(2,k,5,n) || !check(3,l,5,n) || !check(4,m,5,n))continue;
- else
- for(p=0;p<8;++p) {
- if(!check(0,i,6,p) || !check(1,j,6,p) || !check(2,k,6,p) || !check(3,l,6,p) || !check(4,m,6,p) || !check(5,n,6,p))continue;
- else
- for(q=0;q<8;++q) {
- if(!check(0,i,7,q) || !check(1,j,7,q) || !check(2,k,7,q) || !check(3,l,7,q) || !check(4,m,7,q) || !check(5,n,7,q) || !check(6,p,7,q))continue;
- if(check(0,i,7,q) && check(1,j,7,q) && check(2,k,7,q) && check(3,l,7,q) && check(4,m,7,q) && check(5,n,7,q) && check(6,p,7,q)) {
- int hl,vl,kl=1;
- sprintf(s,"Positions=%d %d %d %d %d %d %d %d",i,j,k,l,m,n,p,q);
- outtextxy(10,10,s);
- setcolor(15);
- for(hl=100;hl<500;hl+=50)
- for(vl=50;vl<450;vl+=50)
- rectangle(hl,vl,hl+50,vl+50);
- setfillstyle(SOLID_FILL,15);
- for(hl=120;hl<500;hl+=100)
- for(vl=70;vl<450;vl+=100)
- floodfill(hl,vl,15);
- for(hl=170;hl<500;hl+=100)
- for(vl=120;vl<450;vl+=100)
- floodfill(hl,vl,15);
- setcolor(6);
- setfillstyle(SOLID_FILL,6);
- for(hl=120;hl<500;hl+=100)
- for(vl=120;vl<450;vl+=100)
- floodfill(hl,vl,15);
- for(hl=170;hl<500;hl+=100)
- for(vl=70;vl<450;vl+=100)
- floodfill(hl,vl,15);
- drawqueen(findpos(i),50);
- drawqueen(findpos(j),100);
- drawqueen(findpos(k),150);
- drawqueen(findpos(l),200);
- drawqueen(findpos(m),250);
- drawqueen(findpos(n),300);
- drawqueen(findpos(p),350);
- drawqueen(findpos(q),400);
- ++c;
- getch();
- getch();
- cleardevice();
- }
- }
- }
- }
- }
- }
- }
- }
- }
- getch();
- closegraph();
- gotoxy(getmaxx()/2,getmaxy()/2);
- printf(" No of solutions=%d",c);
- getch();
- };
- int check(int h1,int v1,int h2,int v2) {
- int i,k=v1,f=1;
- if(v1==v2)
- f=0;
- for(i=h1;i<h2;++i)
- ++k;
- if(v2==k)
- f=0;
- k=v1;
- for(i=h1;i<h2;++i)
- --k;
- if(v2==k)
- f=0;
- return(f);
- }
- void drawqueen(int x,int y) {
- setcolor(14);
- arc(x,y,270,360,25);
- arc(x+50,y,180,270,25);
- line(x+10,y+50,x+40,y+50);
- line(x,y+25,x+10,y+50);
- line(x+50,y+25,x+40,y+50);
- circle(x+25,y,4);
- setfillstyle(SOLID_FILL,14);
- floodfill(x+20,y+40,14);
- setcolor(4);
- circle(x+25,y,2);
- line(x+5,y+40,x+45,y+40);
- }
- int findpos(int i) {
- switch(i) {
- case 0:return(100);
- case 1:return(150);
- case 2:return(200);
- case 3:return(250);
- case 4:return(300);
- case 5:return(350);
- case 6:return(400);
- case 7:return(450);
- }
- }
Add Comment
Please, Sign In to add comment