2722: The number of sum

Description
Given a sequence of positive integers, determines how many number, equal to the number of columns and the other two numbers. For example, the number of columns for 1234, the answer to this question is 2 because 2 + 1 = 3, 4 + 1 = 3.

Input
total of two lines, the first line number n is the number of column number (1 <= n <= 100 ), the second row by n number of columns is a positive integer not greater than 10,000 consisting of two integers between adjacent separated by a single space.
Output
an integer, i.e., the number of columns is equal to the counted number and the other of the two numbers.
Sample input
. 4
. 1 2. 4. 3

#include <cstdio>
#include <iostream>
using namespace std;
int a[105];
int main() {
    int n, ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++){
        bool f = false;
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                if(i != j && i != k && j != k && a[i] == a[j] + a[k]){
                    f = true;
				}
            }
		}
        if(f == true)
            ans++;
	}
    cout << ans;
    return 0;
}

At that time, always I thought it was a universal set of the semi-finals of the year noip true problem, but could not find, do not know myself remember.

Published 15 original articles · won praise 10 · views 214

Guess you like

Origin blog.csdn.net/qq_39053800/article/details/104240712