[問題] 和內塔公式
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
c++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
餵入的資料(Input):s
#include <stdio.h>
#include <stdlib.h>
void move(int n,char A,char B,char C);
int times=0; //全域變數
int main()
{
int n;
printf("請輸入A柱中的環個數: ");
scanf("%d", &n);
move(n,'A','B','C');
printf("共需%d個步驟\n", times);
system("PAUSE");
return 0;
}
void move(int n,char A,char B,char C)
{
if(n==1)
{
printf("ring %d : %c=>%c\n",n,A,C);
times++;
}
else
{
move(n-1,A,C,B);
printf("ring %d : %c=>%c\n",n,A,C);
times++;
move(n-1,B,A,C);
}
}
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
補充說明(Supplement):
else
{
move(n-1,A,C,B);
printf("ring %d : %c=>%c\n",n,A,C);
times++;
move(n-1,B,A,C);
}
}
move(n-1,A,C,B);
我想請問這邊的A為甚麼會是把n-1個從A移動到B,他程式是怎麼操作的
另外這邊的A是指move(n,'A','B','C'); 這邊的A嗎?
還是指這邊的A void move(int n,char A,char B,char C)
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.120.25.238
推
10/24 10:59, , 1F
10/24 10:59, 1F
→
10/24 11:00, , 2F
10/24 11:00, 2F
→
10/24 18:11, , 3F
10/24 18:11, 3F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章