Автор | Сообщение |
|
Отправлено: 08.11.14 07:03. Заголовок: combinations find in 1d array
how can i display only same value starting and ending groups in a 1d array this is the example array int a[12]={2,1,1,2,2,4,5,4,5,4,5,4}; i need to find all combination in this array output ......... 2,1,1,2 4,5,4 5,4,5 4,5,4 5,4,5 4,5,4
|
|
|
Ответов - 5
[только новые]
|
|
|
Отправлено: 08.11.14 07:26. Заголовок: Why are there absent..
Why are there absent combinations 1 1 and 2 2?
|
|
|
|
Отправлено: 09.11.14 08:20. Заголовок: for example this is ..
for example this is a combination 4 5 4 a combination need its first value and last value matching and also minimum three value below combinations i don't want to pick 1 1 1 1 2 5 1 1 1
|
|
|
|
Отправлено: 09.11.14 08:30. Заголовок: I have not understoo..
I have not understood why this combination 1 2 5 1 does not satisfy the condition? Is it because 2 and 5 are unequal each other?
|
|
|
|
Отправлено: 09.11.14 11:24. Заголовок: If I have understood..
If I have understood correctly what you need is the following #include <iostream> #include <algorithm> #include <iterator> #include <functional> template <typename ForwardIterator> void display_ranges( ForwardIterator first, ForwardIterator last, std::ostream &os = std::cout ) { typedef typename std::iterator_traits<ForwardIterator>::value_type value_type; ForwardIterator next; first = std::adjacent_find( first, last, std::not_equal_to<value_type>() ); if ( first != last ) { while ( ( next = std::adjacent_find( std::next( first ), last, std::not_equal_to<value_type>() ) ) != last ) { if ( *first == *std::next( next ) ) { std::copy( first, std::next( next, 2 ), std::ostream_iterator<value_type>( os, " " ) ); os << std::endl; } first = next; } } } int main() { int a[] = { 2, 1, 1, 2, 2, 4, 5, 4, 5, 4, 5, 4 }; display_ranges( std::begin( a ), std::end( a ) ); return 0; } The output will be 2 1 1 2 4 5 4 5 4 5 4 5 4 5 4 5 4 5 4
|
|
|
|
Отправлено: 09.11.14 17:21. Заголовок: yes exactly what i n..
yes exactly what i needed thank's
|
|
|
|