1次元配列
このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
English
A list of the same type
- An array holds a fixed number of values of one type.
- The guide's lower bound is 1 unless a question says otherwise.
- One index, in square brackets, picks an element.
DECLARE Temp : ARRAY[1:7] OF INTEGER
Temp[1] ← 18
Temp[7] ← 25
OUTPUT "Monday: ", Temp[1]
OUTPUT "Sunday: ", Temp[7]
English
A loop visits every cell
- A
FORloop from the lower bound to the upper bound is how you fill or read the array.
English
DECLARE Temp : ARRAY[1:5] OF INTEGER
DECLARE Day, Highest, HotDay : INTEGER
Temp[1] ← 18
Temp[2] ← 21
Temp[3] ← 17
Temp[4] ← 24
Temp[5] ← 19
Highest ← Temp[1]
HotDay ← 1
FOR Day ← 2 TO 5
IF Temp[Day] > Highest THEN
Highest ← Temp[Day]
HotDay ← Day
ENDIF
NEXT Day
OUTPUT "Highest: ", Highest, " on day ", HotDay
Higheststarts as the first cell, so the loop starts at day 2.HotDaystores the index, andHigheststores the value in that cell.
English
Watch out
Score[1]is the first cell when the array was declared[1:5].- The index can be an expression:
Score[I + 1].
English
Common mistakes
For a maximum search, a stored candidate represents the best item seen so far. Trace an all-negative array: an initial candidate that is not an array item can give a wrong result.
- Declare the array before you store into a cell.
- The index must stay inside the declared bounds.
English
Now you try
- Store numbers in cells, then total them with a
FORloop:Totalstarts at 0 before the loop.
English
Independent transfer
The final task has no supplied algorithm. Plan its inputs, processing and outputs, then solve it before opening support. Check more than the sample case.
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
ScoreをARRAY[1:3] OF INTEGERとして宣言します。セル1に4を格納し、そのセルを出力します。
実行ボタンをクリックして出力を確認してください。
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
配列は既に入力されています。3つの値を合計して総計(18)を出力します。
実行ボタンをクリックして出力を確認してください。
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
NumberOfValues (1 から 6) を読み込み、NumberOfValues 個の整数を配列に入力します。奇数がいくつあるかを出力します。値は負になることがあります。
実行ボタンをクリックして出力を確認してください。