問題プレビューID: e0daf680応用情報技術者試験 2009年(平成21年度)春期 午前
問 7
応用情報技術者試験 2009年(平成21年度)春期 午前文字列を引数とする関数 len,first,butfirst を用いて,関数 comp を再帰的に定義した。comp("11", "101") を呼び出したとき,返されるものはどれか。
〔関数の定義〕
- len(S):文字列 S の長さを返す。S が空文字列のときは 0 を返す。
- first(S):文字列 S の先頭の 1 文字の ASCII コードを返す。S が空文字列のときはエラーを返す。
- butfirst(S):文字列 S の先頭の 1 文字を除いた残りの文字列を返す。S が空文字列のときはエラーを返す。
comp(A, B)
begin
if len(A) = 0 and len(B) = 0 then return 0;
if len(A) = 0 and len(B) ≠ 0 then return 1;
if len(A) ≠ 0 and len(B) = 0 then return −1;
if first(A) < first(B) then return 1;
if first(A) > first(B) then return −1;
return comp(butfirst(A), butfirst(B));
end
関連問題
本文が同じ・似ている問題を表示しています