Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <cmath>
- #include <iostream>
- #include <map>
- #include <set>
- #include <stdexcept>
- #include <string>
- #include <utility>
- #include <vector>
- #include <sstream>
- #include <numeric>
- using namespace std;
- template <typename Container>
- vector<int> Paginate(Container& test_cont, int page_size)
- {
- vector<int> result;
- size_t cont_size = test_cont.size();
- size_t pages_count = cont_size / page_size;
- size_t last_page_size = cont_size - pages_count * page_size;
- if (last_page_size > 0) ++pages_count;
- for (int i=0; i<pages_count; ++i)
- {
- result.push_back(i * page_size);
- }
- for (int i=0; i<pages_count; ++i)
- {
- cout << "page: " << i+1 << endl;
- for (int j = 0; j<page_size; ++j)
- {
- if ((j + i * page_size) < cont_size)
- {
- cout << test_cont[j + i * page_size] << endl;
- }
- else continue;
- }
- }
- return result;
- }
- template <typename It>
- void PrintRange(It range_begin, It range_end) {
- for (auto it = range_begin; it != range_end; ++it) {
- cout << *it << " "s;
- }
- cout << endl;
- }
- int main() {
- size_t size = 77;
- vector<int> test_vector(size);
- iota(test_vector.begin(), test_vector.end(), -100);
- random_shuffle(test_vector.begin(), test_vector.end());
- PrintRange(test_vector.begin(), test_vector.end());
- vector<int> rez = (Paginate(test_vector, 5));
- PrintRange( rez.begin(), rez.end());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement