Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
can be zero
//Title of this code #include <iostream> #include <vector> #include <string> using namespace std; inline int getSign(int flags, int i) { return ((1 << i) & flags) ? 1 : -1; } bool canBeZero(const vector<int>& t) { if (t.size() > 32) return false; int flags = (1 << t.size()) - 1; while (flags > -1) { int sum = 0; for (int i = 0; i < t.size(); ++i) { sum += getSign(flags, i) * t[i]; string s = (getSign(flags, i) == -1) ? "- " : "+ "; cout << s << t[i] << " "; } if (!sum) { cout << " sum is 0"; //return true; } cout << endl; --flags; } return false; } int main() { vector<int> t; t.push_back(3); t.push_back(6); t.push_back(2); t.push_back(1); cout << boolalpha << canBeZero(t); }
run
|
edit
|
history
|
help
0
a simple tuple implementation
NonparaRuns
Power of an element
team name
Test 12(2021)
Rotate90
Optimization Lab 2
Right view of a tree
HelloWorldExample
Value equal to index value