Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionvoid AfficherParties(int n) { if ( n>1 ) AfficherParties(n-1); printf("%d\n", n ); }
#include <set> #include <string> #include using namespace std; typedef set<string> tDico; typedef set<string>::iterator tDicoIter; void anagramme( const string& mot, tDico& liste ) { if ( mot.size() == 1 ) { liste.insert( mot ); return; } for( int pos = 0; pos < mot.size(); ++pos ) { string ana( 1, mot[pos] ); string newM; for ( tDico::size_type j = 0; j < mot.size(); ++j) if ( j != pos ) newM += mot[j]; tDico newList; anagramme( newM, newList ); for ( tDicoIter k = newList.begin(); k != newList.end(); ++k ) { liste.insert( ana + (*k) ); liste.insert( (*k) ); } } } int main( int, char** ) { tDico liste; anagramme( "123", liste ); copy( liste.begin(), liste.end(), ostream_iterator<string>( cout, "\n" ) ); }