Putting it together · 综合运用
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
Putting it together
- A real algorithm joins the pieces: arrays, loops and selection.
- The exam's standard methods are totalling, counting, linear search, and finding the maximum or minimum.
中文
综合运用
- 一个真正的算法把这些部分组合起来:数组、循环和选择。
- 考试的标准方法有:累加、计数、线性查找,以及找最大或最小值。
DECLARE A : ARRAY[1:5] OF INTEGER
DECLARE I, Total : INTEGER
FOR I ← 1 TO 5
A[I] ← I * 10
NEXT I
Total ← 0
FOR I ← 1 TO 5
Total ← Total + A[I]
NEXT I
OUTPUT Total
Explore · 探索
Totalling an array · 对数组累加求和
Totalling — start at 0, then add each array item as the loop visits it. · 累加 —— 从 0 开始,循环每访问一个数组元素就把它加上。
English
Searching and counting
- Linear search: check each item, and set a flag if you find the target.
- Counting: add 1 to a counter each time a rule is true.
中文
查找与计数
- 线性查找:逐个检查,如果找到目标就设一个标志。
- 计数:每当某条规则为真,就给计数器加 1。
DECLARE A : ARRAY[1:5] OF INTEGER
DECLARE I, Target : INTEGER
DECLARE Found : BOOLEAN
FOR I ← 1 TO 5
A[I] ← I * 10
NEXT I
Target ← 30
Found ← FALSE
FOR I ← 1 TO 5
IF A[I] = Target
THEN
Found ← TRUE
ENDIF
NEXT I
OUTPUT Found
English
Common mistakes
- Plan the structure before you write the pseudocode.
- Match the exam's keywords and layout exactly.
中文
常见错误
- 写伪代码前先规划结构。
- 严格对上考试的关键词和格式。
English
Now you try
- Each task uses an array that is filled for you — write the algorithm.
- Press Check answer to test it.
中文
现在轮到你
- 每个任务都用一个已为你填好的数组 —— 写出算法。
- 按检查答案来测试它。
The array A is filled for you. Total all 5 values and output Total = then the total (it is 25). · 数组 A 已为你填好。把全部 5 个值相加,输出 Total = 再接总和(是 25)。
Click Run to see the output here. · 点击“运行”查看此处输出。
The array A is filled for you. Use a linear search · 线性搜索 to set Found to · 到 TRUE if 9 is in the array, then output Found. · 数组 A 已为你填好。用线性查找:如果 9 在数组里,就把 Found 设为 TRUE,然后输出 Found。
Click Run to see the output here. · 点击“运行”查看此处输出。
The array A is filled for you. Count how many values are greater than 4, then output the count (it is 3). · 数组 A 已为你填好。数一数有多少个值大于 4,然后输出这个数量(是 3)。
Click Run to see the output here. · 点击“运行”查看此处输出。