codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <algorithm> #include <functional> #include <iostream> #include <locale> #include <iostream> #include <iterator> /* составить программу для определения длины самой длинной неубывающей подпоследовательности в последовательности чисел */ template <typename T> void find(const T* arr, const size_t N) { typedef typename std::allocator<T>::const_pointer iterator; iterator curr = &arr[0], next, found = arr + N; size_t max_seq = 0; for(; (next = std::adjacent_find(curr, arr+N, std::greater<T>())) != arr+N; std::advance(curr = next, 1)) { const size_t curr_length = std::distance(curr, next) + 1; if (curr_length > max_seq) { max_seq = curr_length; found = curr; } std::advance(curr = next, 1); } const size_t last_length = std::distance(curr, next); if (last_length > max_seq) { max_seq = last_length; found = curr; } std::cout << "самая длинная неубывающая последовательность:" << std::endl; std::copy(found, found + max_seq, std::ostream_iterator<T>(std::cout, " ")); } int main() { setlocale(LC_ALL, ""); int arr[] = {1,2,3,0,1,-1,7,6,5,4,1,1,1,1}; const size_t N = sizeof(arr) / sizeof(arr[0]); find(arr, N); return (0); }
Private
[
?
]
Run code
Submit