U E D R , A S I H C RSS

Eight Queen Problem/조현태2

No older revisions available

No older revisions available



이번엔 정상적인 해결..ㅎㅎ
여전히 잠이 안오는 걸로봐서.. 데블스캠프가 밤낮을 바꾼듯..;;ㅁ;;
~cpp 
#include <iostream>
using namespace std;
int main(){
	char mark[8][8]={0,};
	int x[8]={0,};
	int qeen=0;
	while(qeen!=8){
		if (0==mark[x[qeen]][qeen])
		{
			for (register int i=-7; i<8; ++i)
			{
				if (-1<i)
					mark[x[qeen]][i]=1;//가로
				if (-1<x[qeen]+i && x[qeen]+i<8 && -1<qeen+i && qeen+i<8)
					mark[x[qeen]+i][qeen+i]=1;//대각선
				if (-1<x[qeen]+i && x[qeen]+i<8 && -1<qeen-i && qeen-i<8)
					mark[x[qeen]+i][qeen-i]=1;//대각선
			}
			mark[x[qeen]][qeen]=2;
			++qeen;
			if (8==qeen)
			{
				//출력하고 종료한다.
				for (register int i=0; i<8; ++i){
					for (register int j=0; j<8; ++j){
						if (2==mark[i][j])
							cout << "■";
						else
							cout << "□";
					}
					cout << "\n";
				}
				system("PAUSE");
				break;
			}
		}
		else
		{
			++x[qeen];
			if (8==x[qeen])
			{
				while (8==x[qeen])
				{
					x[qeen]=0;
					qeen--;
					if(-1==qeen)
					{
						cout << "검색에 실패하였습니다.";
						return 0;
					}
					++x[qeen];
				}
				for(register int i=0; i<8; ++i)
					for(register int j=0; j<8; ++j)
						mark[i][j]=0;
				qeen=0;
			}
		}
	}
	return 0;
}


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-05-27 07:09:19
Processing time 0.0862 sec