int main(int argc, char* argv[]) { int i = 0; printf("add one: %d\n", addOne(i)); printf("add two: %d\n", addTwo(i)); return i; }
void flagOptions::completeSummary(int count, int other, bool summ){ int mult = count * other; while(summ){ shares += count; completed = addOne(completed); transfer = addTwo(transfer, mult); for(int i = 0; i < 2; i++) commision = ((count*other) / 100 )+ commision; return; } }
string addBinary(string a, string b) { vector<int> va, vb; for (auto c : a) va.push_back(c == '1'); for (auto c : b) vb.push_back(c == '1'); std::reverse(va.begin(), va.end()); std::reverse(vb.begin(), vb.end()); int maxSize = std::max(va.size(), vb.size()); va.resize(maxSize, 0); vb.resize(maxSize, 0); int carry = 0; int res = 0; vector<int> vres; for (int i = 0; i < maxSize; i++) { res = addTwo(va[i], vb[i], carry); vres.push_back(res); } if (carry) vres.push_back(carry); std::reverse(vres.begin(), vres.end()); string s; for (auto d : vres) s += (d == 0 ? string("0") : string("1")); return s; }
bool isAdditiveNumber(string &num) { int numlen=num.size(); for (int p=1; p < numlen; ++p) { for (int q=p+1; q < numlen; ++q) { int i1=0, i2=p, i3=q, i4; if (!isValid(i1, i2, num) || !isValid(i2, i3, num)) { continue; } for (; i3 < numlen; ) { i4 = addTwo(i1, i2, i3, num); if (-1==i4 || !isValid(i3, i4, num)) { break; } i1 = i2; i2 = i3; i3 = i4; } if (i3 == numlen) { return true; } } } return false; }