@[风元元](/space/show?uid=166472) 把system("pause");去掉
by zxz_sword @ 2019-05-30 18:45:44
看成了“我是真滴滴不会哭了”
by HRLYB @ 2019-05-30 18:49:02
题目问的是“其中有多少个数,恰好等于集合中另外两个(不同的)数之和?”只需要统计有多少个数就可以了,只要满足c=a+b中c的个数就可以了
by bigmurmur @ 2019-05-30 18:50:21
'''cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int count = 0;
int n;
int b;
vector<int> a;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> b;
a.push_back(b);
}
sort(a.begin(), a.end());
for (int i = 0; i < a.size(); i++) {bool ok=0;
for (int y = 0; y < i; y++) {
for (int z = y + 1; z < i; z++) {
if (a[i] == a[y] + a[z]) {ok=1;
count++;
break;
}
}if(ok) break;
}
}
cout << count;
system("pause");
return 0;
}
'''
by bigmurmur @ 2019-05-30 18:54:02
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int count = 0;
int n;
int b;
vector<int> a;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> b;
a.push_back(b);
}
sort(a.begin(), a.end());
for (int i = 0; i < a.size(); i++) {
bool ok=0;
for (int y = 0; y < i; y++) {
for (int z = y + 1; z < i; z++) {
if (a[i] == a[y] + a[z]) {
count++;
ok=1;
break;
}
}
if(ok) break;
}
}
cout << count;
system("pause");
return 0;
}
```
by bigmurmur @ 2019-05-30 19:01:13
@[bigmurmur](/space/show?uid=113959) okkkkk,谢谢大佬解决啦
by 风元元 @ 2019-05-30 19:03:00