Форум » C/C++ для начинающих (C/C++ for beginners) » ­ How to distribute a value into vector » Ответить

­ How to distribute a value into vector

ramees: [pre2] #include <iostream> #include <vector> #include <algorithm> template <typename T, typename ForwardIterator> bool increment(ForwardIterator first, ForwardIterator last, T maximum) { for (auto it = first; it != last; ++it) { if (*it != maximum) { std::fill(first, it, ++*it); return true; } } return false; } int main() { int minimum = 1; // included int slots = 3; int sum = 8; int internal_max = sum - slots * minimum; std::vector<int> vect(slots - 1, 0); do { auto previous_pos = internal_max; for (auto it = vect.begin(); it != vect.end(); ++it) { auto val = previous_pos - *it + minimum; previous_pos = *it; std::cout << val << " "; } std::cout << previous_pos + minimum << std::endl; } while (increment(vect.begin(), vect.end(), internal_max)); } [/pre2] hi i need a little help how can i control each slot with a capacity value example if the slots = 3,and sum= 8 then i like to add a capacity (array or vector) = [4][2][3] all the sequence must be inside this range­

Ответов - 0



полная версия страницы