#include <bits/stdc++.h>
using namespace std;
int main()
{
int a[100] = {0};
int n, m = 0, temp;
cin >> n;
int i, j;
for (i = 0; i < n; i++)
{
cin >> a[i];
}
for (i = 0; i < n - 1; i++)
{
for (j = 0; j < n - i - 1; j++)
{
if (a[j] > a[j + 1])
{
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
for (i = 0, j = 1, temp = n - 1; temp >= 2;)
{
if (a[i] + a[j] == a[temp])
{
m++;
temp--;
i = 0, j = 1;
}
else
{
if (j < temp - 1)
{
j++;
}
else
{
if (i < j - 1)
{
i++;
j = i + 1;
}
else
{
temp--;
i = 0, j = 1;
}
}
}
}
cout << m;
}
P2141 [NOIP2014 普及组] 珠心算测验
最新推荐文章于 2024-09-10 15:28:21 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)