Last active
August 29, 2015 14:08
-
-
Save r0mdau/38886af40c68a64bf3da to your computer and use it in GitHub Desktop.
Calculateur d'anagramme en c++. Charge un dictionnaire en mémoire et calcule autant d'anagrammes que l'on souhaite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <cstring> | |
#include <fstream> | |
#include <list> | |
using namespace std; | |
bool sontAnagrammes( const char * c_saisie , const char * c_mot ) | |
{ | |
string caracters( c_saisie ); | |
string mot( c_mot ); | |
sort( caracters.begin() , caracters.end() ); | |
sort( mot.begin() , mot.end() ); | |
return caracters == mot; | |
} | |
int main() | |
{ | |
ifstream fichier("french.dic", ios::in); | |
list<string> dico; | |
if(fichier) | |
{ | |
string mot; | |
while(getline(fichier, mot)){ | |
dico.push_back(mot); | |
} | |
fichier.close(); | |
} else { | |
cerr << "Impossible d'ouvrir le fichier !" << endl; | |
} | |
while(true){ | |
string caracters; | |
cout << endl << "Votre mot : "; | |
cin >> caracters; | |
if(caracters == "exit") break; | |
for(list<string>::const_iterator iterator = dico.begin(), end = dico.end(); iterator != end; ++iterator){ | |
string mot = *iterator; | |
if(sontAnagrammes(caracters.c_str(), mot.c_str())){ | |
cout << endl << mot.c_str(); | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment