Information
- ID
- 671
- Time
- 1000ms
- Memory
- 16MiB
- Difficulty
- 10
- Tags
- # Submissions
- 3
- Accepted
- 2
- Uploaded By
#include<bits/stdc++.h>
using namespace std;
/*
数组计数法
1、循环所有的数对
2、使用r数组来统计哪些数出现过
*/
int a[60],r[30];
int n, c = 0;//c:统计出现过的数有几个
int main()
{
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
//循环所有的数对
for(int i = 1; i <= n; i++){
for(int j = i+1; j <= n; j++){
r[a[i]+a[j]]++;
//如果a[i]+a[j]这个数是第一次出现
if(r[a[i]+a[j]] == 1){
c++;
}
}
}
cout << c << endl;
//循环输出出现过的数
//任意从1~13中找2个数相加,和是2~26范围的数
for(int i = 2; i <= 26; i++){
if(r[i] != 0){
cout << i << " ";
}
}
return 0;
}
By signing up a 追梦算法网 universal account, you can submit code and join discussions in all online judging services provided by us.