返回学习页
知识点指南

Implementation

Implementation is the base skill of turning a story into exact code. The goal is not to invent a special algorithm, but to read carefully, choose clear variables, and apply the stated rules without drifting away from the task.

什么时候使用

读题时可以留意这些信号。

  • The problem gives direct rules and asks you to follow them carefully.
  • The main work is input, conditions, loops, counters, and output.
  • The story has small details like equality, first/last item, or special words.

常见错误

提交前可以检查这些小陷阱。

  • Skipping edge cases like ties, first item, last item, or equality.
  • Using a variable for two different meanings.
  • Printing an intermediate value instead of the final requested answer.

怎么写成代码

把知识点翻译成变量、循环、判断和更新。

  • Create variables whose names match the story objects, such as count, answer, current, best, or total.
  • Read input in the same shape as the statement: single value, list, string, grid, or pairs.
  • Use if statements to express story rules, and update only the variable that the rule affects.
  • Print exactly the requested final value or decision word.

在 Block 题里长什么样

答题时通常会看到这些步骤被拆成代码块。

  1. 1Read the input values.
  2. 2Initialise the answer or state.
  3. 3Process each required value.
  4. 4Apply the condition from the story.
  5. 5Update the answer.
  6. 6Print the answer.

题目里怎么出现

读题时先找这些信号,再决定答案区应该选哪些 blocks。

  • The story asks for a direct count, maximum, minimum, yes/no decision, or constructed string.
  • There is one clear rule and little interaction between far-apart items.
  • The sample explanation mostly checks whether the rule was followed exactly.

Count values that pass a rule

一个小型模板,展示代码和 blocks 的对应关系。

C++

int answer = 0;
for (int x : values) {
    if (x >= limit) {
        answer++;
    }
}
cout << answer << '\n';

Python

answer = 0
for x in values:
    if x >= limit:
        answer += 1
print(answer)

对应 block 顺序

  1. 1Read N and the rule value.
  2. 2Initialise answer to 0.
  3. 3Loop through the N records.
  4. 4Check whether the current record satisfies the rule.
  5. 5Increase answer when it does.
  6. 6Output answer.

建议先练这道题

可以先从 Soccer Match 开始,再回到这里复盘知识点信号。

打开题目