20分求助,已考虑重复的情况,还是过不了
查看原帖
20分求助,已考虑重复的情况,还是过不了
1027350
Etayo楼主2023/12/28 20:07
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int n;
    int count = 0;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n,0);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = n - 1; i > 1; i--)
    {
        for (int j = 0; j < i - 1; j++)
        {
            for (int z = j + 1; z < i; z++)
            {
                if (a[z] + a[j] == a[i])
                {
                   b[i]=1;
                   break;
                }
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        if(b[i]==1)
        {
            count++;
        }
    }
    cout << count;
    return 0;
}


2023/12/28 20:07
加载中...