在不改變最後輸出(print)的狀況下,請使用指令While 取代指令Repeat,重新書
寫下列片段的虛擬碼(pseudocode),其中粗體字為指令之關鍵字。(15 分)
Assign Sum the value 1;
Repeat (Print the value assigned to Sum;
Assign Sum the value Sum+1)
until (Sum = 5)
執行下列遞迴(Recursion)程式,並回答下列各題:
public class CrazyR
{
public static void R(int n, int t)
{
if (n == 0)
{
StdOut.print(t + " ");
return;
}
R(n-1, 3*t);
R(n-1, 3*t+2);
R(n-1, 3*t+1);
}
public static void main(String[] args)
{
R(2, 0);
StdOut.println();
}
}
程式執行時會產生那些遞迴呼叫(Recursive call),依執行順序畫出其樹狀結構。(8 分)
程式在執行後依序列出輸出的數字。(4 分)
A
B
A
B
A
B
A
B
OR
OR
OR
OR
AND
AND
NOT
NOT
NOT
NOT
NOT
NOT
AND
output
output
output
output
103年公務人員高等考試三級考試試題
代號:
全一張
(背面)
22750、26550
26650、26750