소스 보기
#include "stdio.h" #include "conio.h" int LowCheck(int befLine, int NewLine); int ExceptLine(int iTier, int iSPoint, int iExceptLine); const int iRow[8][10] = { { 5, 3, 2, 4, 7, 8, 1, 3, 3, 6 }, { 3, 2, 2, 5, 5, 7, 6, 5, 1, 1 }, { 8, 8, 1, 1, 1, 9, 3, 4, 6, 2 }, { 3, 4, 7, 8, 5, 2, 1, 9, 5, 2 }, { 2, 3, 5, 9, 3, 9, 3, 5, 2, 1 }, { 7, 5, 1, 2, 2, 5, 7, 6, 4, 1 }, { 4, 2, 6, 5, 8, 8, 8, 2, 2, 3 }, { 1, 3, 2, 4, 4, 3, 3, 9, 2, 5 } }; void main() { int iLowLine[8], iLowNumber = 10, iTierCount, iTemp, iLineTemp[2], iResult = 0; for(iTierCount = 0; iTierCount < 8; iTierCount++) { iLowLine[iTierCount] = ExceptLine(iTierCount, 0, -1); if(iTierCount > 0) { for(iTemp = 0; iTemp < iTierCount; iTemp++) { if(iLowLine[iTierCount] == iLowLine[iTemp]) { //iLowLine[iTemp] = ExceptLine(iTemp, iLowLine[iTemp], iLowLine[iTemp]); iLineTemp[0] = ExceptLine(iTemp, 0, iLowLine[iTemp]); if(iRow[iTemp][iLineTemp[0]] == 1) iLowLine[iTemp] = iLineTemp[0]; iLineTemp[1] = ExceptLine(iTierCount, 0, iLowLine[iTierCount]); if(iLineTemp[0] > iLineTemp[1]) iLowLine[iTemp] = iLineTemp[0]; else iLowLine[iTierCount] = iLineTemp[1]; } } } iResult = iResult + iRow[iTierCount][iLowLine[iTierCount]]; } for(iTemp = 0; iTemp < 8; iTemp++) { printf("LowLine : %d, LowNumber : %d\n", iLowLine[iTemp], iRow[iTemp][iLowLine[iTemp]]); } printf("\nResult = %d", iResult); getch(); } int LowCheck(int befLine, int NewLine) { return (befLine > NewLine) ? NewLine : befLine; } int ExceptLine(int iTier, int iSPoint, int iExceptLine) { int iLineCount, iLowNumber, iLowLine, iTemp; iLowNumber = 10; for(iLineCount = iSPoint; iLineCount < 10; iLineCount++) { iTemp = iLowNumber; if(((iExceptLine == -1) || (iLineCount != iExceptLine)) && (iLowNumber = LowCheck(iLowNumber, iRow[iTier][iLineCount])) != iTemp) { iLowLine = iLineCount; } } return iLowLine; }