/
Oppq
/
Labs
Обзор
Документация
Войти
/
Oppq
/
Labs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Lab6/Mook.cpp
132 строки
3 KB
Oppq
update: Mook.cpp
01 апр 2026, 19:01
Верифицирован
01 апр 2026, 19:01
e65c2ac
Код
Авторство
О чём код?
// Тема "Последовательные контейнеры" - Задание 9 #include <fstream> #include <iostream> #include <list> using namespace std; template<typename it> size_t max_increasing_len(it first, it last) { if (first == last) return 0; size_t maxl = 1; size_t curl = 1; for (auto it = first; it != last; ++it) { auto next = it; ++next; if (next == last) break; if (*it < *next) { curl++; if (curl > maxl) { maxl = curl; } } else { curl = 1; } } return maxl; } int main() { list<int> const l1 = { 7,8,9,4,5,6,1,2,3,4 }; cout << max_increasing_len(l1.begin(), l1.end()) << "\n"; // 4 list<int> const l2 = { -3,-2,-1,0,0,1,2,3,4,5 }; cout << max_increasing_len(l2.begin(), l2.end()); // 6 return 0; } // Тема "Алгоритмы" - задание 14 #include <algorithm> #include <iostream> #include <vector> // Нужен вектор, т.к. итераторы const using namespace std; // template<class Iterator> // size_t count_permutations(Iterator p, Iterator q) bool matchel(const vector<int>& el) { for (size_t i = 1; i < el.size(); i++) { if (el[i] == el[i - 1]) { return true; } // Найдены одинаковые } return false; } size_t count_permutations(vector<int>::iterator first, vector<int>::iterator last) { vector<int> el(first, last); sort(el.begin(), el.end()); size_t c = 0; do { // Если в этой перестановке нет одинаковых подряд if (!matchel(el)) { c++; } } while (next_permutation(el.begin(), el.end())); return c; } int main() { vector<int> a1 = { 1, 2, 3 }; size_t c1 = count_permutations(a1.begin(), a1.end()); cout << "Перестановок без одинаковых подряд: " << c1 << endl; // 6 vector<int> a2 = { 1, 2, 3, 4, 4 }; size_t c2 = count_permutations(a2.begin(), a2.end()); cout << "Перестановок без одинаковых подряд: " << c2 << endl; // 36 return 0; } // Тема "Алгоритмы" - задание 9 #include <iostream> #include <vector> using namespace std; template<class FwdIt> FwdIt remove_nth(FwdIt p, FwdIt q, size_t n) { if (p == q) return q; size_t count = 0; for (auto it = p; it != q; ++it) { if (count == n) { auto next = it; ++next; for (; next != q; ++it, ++next) *it = *next; return it; } ++count; } return q; }