C++20 sections · 1024 units
Open in Course

Young Physicist - Algorithm

Breaking down the solution

Here's your approach:

1.1. Define a struct with three integer fields: x, y, z.

2.2. Create a sum variable of this struct type, initialized to (0, 0, 0).

3.3. Read nn, the number of forces.

4.4. Loop nn times. For each iteration, read three integers representing a force. Add each component to the corresponding field in sum.

5.5. After the loop, check if sum.x == 0 && sum.y == 0 && sum.z == 0. If true, print YES. Otherwise, print NO. The struct makes this clean. You could use three separate variables, but bundling them shows they're related. This pattern scales to more complex data.