Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / C++ [игнор отключен] [закрыт для гостей] / програмка для перебора / 2 сообщений из 2, страница 1 из 1
20.10.2005, 11:08
    #33334574
johjohn
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
програмка для перебора
Нужна прога, которая перебирает все вариации заданных слов.

Входные параметры: 10 слов
На выходе: текстовый документ со всеми вариантами перестановок.

Или хотябы алгоритм подскажите :)
...
Рейтинг: 0 / 0
20.10.2005, 11:22
    #33334621
rikman
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
програмка для перебора
MSDN rulez:
// next_permutation.cpp
// compile with: /EHsc
// Illustrates how to use the next_permutation function.
//
// Functions:
// next_permutation : Change the order of the sequence to the
// next lexicograhic permutation.

// disable warning C4786: symbol greater than 255 character,
// okay to ignore
#pragma warning(disable: 4786)

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>

using namespace std ;

int main()
{
const int VECTOR_SIZE = 3 ;

// Define a template class vector of strings
typedef vector<string> StrVector ;

//Define an iterator for template class vector of strings
typedef StrVector::iterator StrVectorIt ;

//Define an ostream iterator for strings
typedef ostream_iterator<string> StrOstreamIt;

StrVector Pattern(VECTOR_SIZE) ;

StrVectorIt start, end, it ;

StrOstreamIt outIt(cout, " ") ;

start = Pattern.begin() ; // location of first
// element of Pattern

end = Pattern.end() ; // one past the location last
// element of Pattern

//Initialize vector Pattern
Pattern[0] = "A" ;
Pattern[1] = "B" ;
Pattern[2] = "C" ;

// print content of Pattern
cout << "Before calling next_permutation:\n" << "Pattern: " ;
for(it = start; it != end; it++)
cout << *it << " " ;
cout << "\n\n" ;

// Generate all possible permutations

cout << "After calling next_permutation:" << endl ;
while ( next_permutation(start, end) )
{
copy(start, end, outIt) ;
cout << endl ;
}
}

Output
Before calling next_permutation:
Pattern: A B C

After calling next_permutation:
A C B
B A C
B C A
C A B
C B A
...
Рейтинг: 0 / 0
Форумы / C++ [игнор отключен] [закрыт для гостей] / програмка для перебора / 2 сообщений из 2, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]