<div>일단 본삭금</div> <div> </div><pre style="margin:0px;line-height:125%;"><span style="color:rgb(136,136,136);">#include <stdio.h></span> <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">탑에</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">몇개의</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">원판이</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">있는지</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">변수</span><span style="color:rgb(0,112,32);">int</span> nplates[<span style="color:rgb(0,0,221);font-weight:bold;">3</span>]; <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">어떤</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">원판이</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">있는지</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">보관</span><span style="color:rgb(51,51,51);">//</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">탑의</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">현재</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">상태를</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">표시</span><span style="color:rgb(0,112,32);">int</span> tower[<span style="color:rgb(0,0,221);font-weight:bold;">3</span>][<span style="color:rgb(0,0,221);font-weight:bold;">100</span>]; void print_tower() { <span style="color:rgb(0,112,32);">int</span> i; <span style="color:rgb(51,51,51);">//</span>tower[][] <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">내용을</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">보여준다</span> A B C <span style="color:rgb(0,136,0);font-weight:bold;">for</span> (i <span style="color:rgb(51,51,51);">=</span> <span style="color:rgb(0,0,221);font-weight:bold;">1</span>; i <span style="color:rgb(51,51,51);"><</span> <span style="color:rgb(0,0,221);font-weight:bold;">5</span>; i<span style="color:rgb(51,51,51);">++</span>){ <span style="color:rgb(0,136,0);font-weight:bold;">if</span> (i <span style="color:rgb(51,51,51);">==</span> <span style="color:rgb(0,0,221);font-weight:bold;">1</span>) printf(<span style="background-color:rgb(255,240,240);">"</span><span style="color:rgb(102,102,102);font-weight:bold;background-color:rgb(255,240,240);">\n</span><span style="background-color:rgb(255,240,240);">A :"</span>); printf(<span style="background-color:rgb(255,240,240);">"</span><span style="background-color:rgb(238,238,238);">%d</span><span style="background-color:rgb(255,240,240);"> "</span>, tower[<span style="color:rgb(0,0,221);font-weight:bold;">0</span>][i]); } <span style="color:rgb(0,136,0);font-weight:bold;">for</span> (i <span style="color:rgb(51,51,51);">=</span> <span style="color:rgb(0,0,221);font-weight:bold;">1</span>; i <span style="color:rgb(51,51,51);"><</span> <span style="color:rgb(0,0,221);font-weight:bold;">5</span>; i<span style="color:rgb(51,51,51);">++</span>){ <span style="color:rgb(0,136,0);font-weight:bold;">if</span> (i <span style="color:rgb(51,51,51);">==</span> <span style="color:rgb(0,0,221);font-weight:bold;">1</span>) printf(<span style="background-color:rgb(255,240,240);">"</span><span style="color:rgb(102,102,102);font-weight:bold;background-color:rgb(255,240,240);">\n</span><span style="background-color:rgb(255,240,240);">B :"</span>); printf(<span style="background-color:rgb(255,240,240);">"</span><span style="background-color:rgb(238,238,238);">%d</span><span style="background-color:rgb(255,240,240);"> "</span>, tower[<span style="color:rgb(0,0,221);font-weight:bold;">1</span>][i]); } <span style="color:rgb(0,136,0);font-weight:bold;">for</span> (i <span style="color:rgb(51,51,51);">=</span> <span style="color:rgb(0,0,221);font-weight:bold;">1</span>; i <span style="color:rgb(51,51,51);"><</span> <span style="color:rgb(0,0,221);font-weight:bold;">5</span>; i<span style="color:rgb(51,51,51);">++</span>){ <span style="color:rgb(0,136,0);font-weight:bold;">if</span> (i <span style="color:rgb(51,51,51);">==</span> <span style="color:rgb(0,0,221);font-weight:bold;">1</span>) printf(<span style="background-color:rgb(255,240,240);">"</span><span style="color:rgb(102,102,102);font-weight:bold;background-color:rgb(255,240,240);">\n</span><span style="background-color:rgb(255,240,240);">C :"</span>); printf(<span style="background-color:rgb(255,240,240);">"</span><span style="background-color:rgb(238,238,238);">%d</span><span style="background-color:rgb(255,240,240);"> "</span>, tower[<span style="color:rgb(0,0,221);font-weight:bold;">2</span>][i]); } <span style="color:rgb(51,51,51);">//</span> <span style="color:rgb(51,51,51);">...</span> printf(<span style="background-color:rgb(255,240,240);">"</span><span style="color:rgb(102,102,102);font-weight:bold;background-color:rgb(255,240,240);">\n</span><span style="background-color:rgb(255,240,240);">"</span>); printf(<span style="background-color:rgb(255,240,240);">"다음 Enter : "</span>); getchar(); <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">아무키나</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">누를때까지</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">대기</span> fflush(stdin); } <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">하나의</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">원판을</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">이동할</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">때</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">마다</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">전체</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">탑의</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">현재</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">상태를</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">변경하고</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">탑의</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">내용을</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">표시</span><span style="color:rgb(51,51,51);">.</span>void move_one(<span style="color:rgb(0,112,32);">int</span> n, char from, char to)<span style="color:rgb(51,51,51);">//</span> n<span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">번</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">원판을</span> from<span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">에서</span> to<span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">로</span> { <span style="color:rgb(51,51,51);">//</span>nplates[](<span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">원판개수</span>) <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">와</span> tower[][] <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">내용을</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">수정한다</span> printf(<span style="background-color:rgb(255,240,240);">"</span><span style="color:rgb(102,102,102);font-weight:bold;background-color:rgb(255,240,240);">\n</span><span style="background-color:rgb(255,240,240);">원판 </span><span style="background-color:rgb(238,238,238);">%d</span><span style="background-color:rgb(255,240,240);">을 </span><span style="background-color:rgb(238,238,238);">%c</span><span style="background-color:rgb(255,240,240);">로 옮긴다.</span><span style="color:rgb(102,102,102);font-weight:bold;background-color:rgb(255,240,240);">\n</span><span style="background-color:rgb(255,240,240);">"</span>, n, from, to); tower[to][nplates[to] <span style="color:rgb(51,51,51);">+</span> <span style="color:rgb(0,0,221);font-weight:bold;">1</span>] <span style="color:rgb(51,51,51);">=</span> tower[from][nplates[from]]; <span style="color:rgb(51,51,51);">//</span>from<span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">에서</span> to<span style="color:rgb(51,51,51);">+</span><span style="color:rgb(0,0,221);font-weight:bold;">1</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">로</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">값보내기</span> tower[from][nplates[from]] <span style="color:rgb(51,51,51);">=</span> <span style="color:rgb(0,0,221);font-weight:bold;">0</span>;<span style="color:rgb(51,51,51);">//</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">보냈던</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">값을</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">지워주기</span> <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(0,136,0);font-weight:bold;">from</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">에서는</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">제일</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">위의</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">원판을</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">빼고</span> <span style="color:rgb(51,51,51);">//</span>to <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">에서는</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">제일</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">끝의</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">원판을</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">추가하고</span> <span style="color:rgb(51,51,51);">//</span>nplates[]<span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">값을</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">감소</span><span style="color:rgb(51,51,51);">/</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">증가</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">한다</span><span style="color:rgb(51,51,51);">.</span> nplates[from] <span style="color:rgb(51,51,51);">-=</span> <span style="color:rgb(0,0,221);font-weight:bold;">1</span>; nplates[to] <span style="color:rgb(51,51,51);">+=</span> <span style="color:rgb(0,0,221);font-weight:bold;">1</span>; <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">이동이</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">발생할</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">때</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">마다</span> print_tower()<span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">호출</span> print_tower(); } <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">타워내용을</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">초기화</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">한다</span><span style="color:rgb(51,51,51);">.</span> <span style="color:rgb(51,51,51);">//</span>start <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">위치에</span> n<span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">개의</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">원판</span>(<span style="color:rgb(0,0,221);font-weight:bold;">1</span><span style="color:rgb(51,51,51);">~</span>n)<span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">이</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">있다</span><span style="color:rgb(51,51,51);">.</span>void init_tower(<span style="color:rgb(0,112,32);">int</span> n, char start) { <span style="color:rgb(0,112,32);">int</span> i, tower_no; <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">탑의</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">번호</span> A,B,C <span style="color:rgb(51,51,51);">-></span> <span style="color:rgb(0,0,221);font-weight:bold;">0</span>,<span style="color:rgb(0,0,221);font-weight:bold;">1</span>,<span style="color:rgb(0,0,221);font-weight:bold;">2</span> tower_no <span style="color:rgb(51,51,51);">=</span> start <span style="color:rgb(51,51,51);">-</span> <span style="background-color:rgb(255,240,240);">'A'</span>; <span style="color:rgb(51,51,51);">//</span>tower[][]<span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">내용과</span> nplates[]<span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">를</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">초기화한다</span><span style="color:rgb(51,51,51);">.</span> tower[<span style="color:rgb(0,0,221);font-weight:bold;">3</span>][<span style="color:rgb(0,0,221);font-weight:bold;">100</span>] <span style="color:rgb(51,51,51);">=</span> {<span style="color:rgb(0,0,221);font-weight:bold;">0</span>};<span style="color:rgb(51,51,51);">//</span> <span style="color:rgb(51,51,51);">-----------------------------</span> <span style="color:rgb(51,51,51);">></span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">구문오류</span> nplates[<span style="color:rgb(0,0,221);font-weight:bold;">3</span>] <span style="color:rgb(51,51,51);">=</span> {<span style="color:rgb(0,0,221);font-weight:bold;">0</span>};<span style="color:rgb(51,51,51);">//</span> <span style="color:rgb(51,51,51);">--------------------------------</span> <span style="color:rgb(51,51,51);">></span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">구문오류</span> <span style="color:rgb(51,51,51);">//</span>tower[<span style="color:rgb(0,0,221);font-weight:bold;">0</span>][<span style="color:rgb(0,0,221);font-weight:bold;">0</span>]<span style="color:rgb(51,51,51);">~</span>[<span style="color:rgb(0,0,221);font-weight:bold;">0</span>][<span style="color:rgb(0,0,221);font-weight:bold;">3</span>] <span style="color:rgb(51,51,51);">=</span> <span style="color:rgb(0,0,221);font-weight:bold;">4</span>,<span style="color:rgb(0,0,221);font-weight:bold;">3</span>,<span style="color:rgb(0,0,221);font-weight:bold;">2</span>,<span style="color:rgb(0,0,221);font-weight:bold;">1</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">식으로</span> <span style="color:rgb(0,136,0);font-weight:bold;">for</span> (i <span style="color:rgb(51,51,51);">=</span> <span style="color:rgb(0,0,221);font-weight:bold;">1</span>; i <span style="color:rgb(51,51,51);"><=</span> n; i<span style="color:rgb(51,51,51);">++</span>) tower[tower_no][i] <span style="color:rgb(51,51,51);">=</span> i; <span style="color:rgb(51,51,51);">//</span>nplates[] <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">에</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">원판의</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">수를</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">기억시킨다</span><span style="color:rgb(51,51,51);">.</span> nplates[tower_no] <span style="color:rgb(51,51,51);">=</span> <span style="color:rgb(0,0,221);font-weight:bold;">0</span>; } void hanoi_tower(<span style="color:rgb(0,112,32);">int</span> n, char from, char tmp, char to) { <span style="color:rgb(0,136,0);font-weight:bold;">if</span> (n <span style="color:rgb(51,51,51);">==</span> <span style="color:rgb(0,0,221);font-weight:bold;">1</span>) <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">제일</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">위에</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">있는</span> <span style="color:rgb(0,0,221);font-weight:bold;">1</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">번</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">원판을</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">이동</span> move_one(<span style="color:rgb(0,0,221);font-weight:bold;">1</span>, from, to); <span style="color:rgb(0,136,0);font-weight:bold;">else</span> { <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(0,0,221);font-weight:bold;">1</span><span style="color:rgb(51,51,51);">~</span>n<span style="color:rgb(51,51,51);">-</span><span style="color:rgb(0,0,221);font-weight:bold;">1</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">을</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">임시</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">장소에</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">이동</span> hanoi_tower(n <span style="color:rgb(51,51,51);">-</span> <span style="color:rgb(0,0,221);font-weight:bold;">1</span>, from, to, tmp); <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">제일</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">밑에</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">있는</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">원판을</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">이동</span> move_one(n, from, to); <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(0,0,221);font-weight:bold;">1</span> <span style="color:rgb(51,51,51);">~</span> n<span style="color:rgb(51,51,51);">-</span><span style="color:rgb(0,0,221);font-weight:bold;">1</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">을</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">임시</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">장소에서</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">목적지로</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">이동</span> hanoi_tower(n <span style="color:rgb(51,51,51);">-</span> <span style="color:rgb(0,0,221);font-weight:bold;">1</span>, tmp, from, to); } } void main() { <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">초기</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">조건</span>, <span style="color:rgb(0,0,221);font-weight:bold;">1</span><span style="color:rgb(51,51,51);">~</span><span style="color:rgb(0,0,221);font-weight:bold;">4</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">원판이</span> A<span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">에</span> <span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">있다</span><span style="color:rgb(51,51,51);">.</span> init_tower(<span style="color:rgb(0,0,221);font-weight:bold;">4</span>, <span style="background-color:rgb(255,240,240);">'A'</span>); printf(<span style="background-color:rgb(255,240,240);">"초기상태"</span>); print_tower(); hanoi_tower(<span style="color:rgb(0,0,221);font-weight:bold;">4</span>, <span style="background-color:rgb(255,240,240);">'A'</span>, <span style="background-color:rgb(255,240,240);">'B'</span>, <span style="background-color:rgb(255,240,240);">'C'</span>); }</pre><pre style="margin:0px;line-height:125%;"> </pre><pre style="margin:0px;line-height:125%;">코드는 이것이구요</pre><pre style="margin:0px;line-height:125%;">하노이타워를 실시간으로 알려주는 프로그램입니다.</pre><pre style="margin:0px;line-height:125%;">어디로 보내고 또 어디로 갔는지..</pre><pre style="margin:0px;line-height:125%;">근데 중간까지는 괜찮았는데 저기 void init_tower(<span style="color:rgb(0,112,32);">int</span> n, char start) 부분에서 구문오류가 나네요,,</pre><pre style="margin:0px;line-height:125%;">전 배열을 초기화 해주고 싶었는데 그게 안됩니다.,.. x[100] = {0,} 이런식으로 썻는데 안되요...</pre><pre style="margin:0px;line-height:125%;">제가 전역에 두고 해서 그런간가요 ㅠㅠ 지금 이게 막혀서 테스트도 못하고있습니다... </pre>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.