March 2023 C/C++ (Level 3) real test analysis#中国电子学院#National Youth Software Programming Level Examination

insert image description here

Problem 1: Sum

Given a sequence of positive integers, determine how many of them are equal to the sum of the other two numbers in the sequence. For example, for the sequence 1 2 3 4, the answer to this question is 2, because 3 = 2 + 1, 4 = 1 + 3.
Time limit: 10000
Memory limit: 65536
Input
a total of two lines, the first line is the number n ( 1 <= n <= 100) of numbers in the sequence, and the second line is a sequence composed of n positive integers not greater than 10000 , separated by a single space between two adjacent integers.
Output
An integer, the number of numbers in the sequence equal to the sum of the other two numbers.
Sample input
4
1 2 3 4
Sample output
2

To solve this problem, we can use two layers of loops to iterate through the elements in the array, and check if the current element is equal to the sum of the other two elements in the inner loop. If yes, increment the counter by 1.

The following is the problem-solving code written in C language:

#include <stdio.h>

Guess you like

Origin blog.csdn.net/gozhuyinglong/article/details/132381550