-
Notifications
You must be signed in to change notification settings - Fork 0
/
#60.cpp
44 lines (38 loc) · 762 Bytes
/
#60.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <string>
#include <sstream>
#include <unordered_set>
#include <vector>
using namespace std;
bool sameSumPartition(vector<int> &arr) {
int total = 0;
for (int i = 0; i < arr.size(); i++) {
total += arr[i];
}
if (total % 2 != 0) return false;
total /= 2;
unordered_set<int> sums;
for (int i = 0; i < arr.size(); i++) {
if (sums.find(total - arr[i]) != sums.end())
return true;
else {
for (int sum : sums) {
sums.insert(arr[i] + sum);
}
sums.insert(arr[i]);
}
}
return false;
}
int main() {
string inp;
while (cin >> inp) {
string token;
istringstream ss(inp);
vector<int> v;
while (getline(ss, token, ',')) {
v.push_back(stoi(token));
}
cout << sameSumPartition(v) << endl;
}
}