TP sur les conteneurs
Moitié du TP XML : parse et test de cercle
This commit is contained in:
parent
3420425f30
commit
8caa238c42
8 changed files with 1083 additions and 5 deletions
88
snippets/compte_mots.cpp
Normal file
88
snippets/compte_mots.cpp
Normal file
|
@ -0,0 +1,88 @@
|
|||
#include <map>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
ifstream is("cyrano.txt");
|
||||
string mot;
|
||||
|
||||
map<string, int> compteMots;
|
||||
|
||||
while (is >> mot)
|
||||
{
|
||||
compteMots[mot]++;
|
||||
}
|
||||
|
||||
is.close();
|
||||
|
||||
multimap<int,string> countMap;
|
||||
|
||||
transform(compteMots.begin(),compteMots.end(),inserter(countMap,countMap.begin()),
|
||||
[](pair<string,int> paire) -> ::pair<int,string>
|
||||
{
|
||||
return make_pair(paire.second,paire.first);
|
||||
});
|
||||
|
||||
for(std::map<string, int>::iterator it = compteMots.begin() ;
|
||||
it != compteMots.end();
|
||||
++it)
|
||||
{
|
||||
if (it->second > 5)
|
||||
{
|
||||
cout << setw(20) << it->first << '\t'
|
||||
<< it->second << endl;
|
||||
}
|
||||
}
|
||||
|
||||
cout << endl << endl;
|
||||
cout << "Compte ordonné croissant" << endl;
|
||||
|
||||
ofstream sortie("Fréquences triées.txt");
|
||||
|
||||
for(const pair<const int,string> & compte : countMap)
|
||||
{
|
||||
if (compte.first > 5)
|
||||
{
|
||||
cout << setw(20) << compte.second << '\t'
|
||||
<< compte.first << endl;
|
||||
sortie << setw(20) << compte.second << '\t'
|
||||
<< compte.first << endl;
|
||||
}
|
||||
}
|
||||
|
||||
sortie.close();
|
||||
|
||||
cout << endl << endl;
|
||||
cout << "Compte ordonné décroissant" << endl;
|
||||
|
||||
for(auto it = countMap.rbegin();it!=countMap.rend();++it)
|
||||
{
|
||||
if((*it).first > 5)
|
||||
{
|
||||
cout << setw(20) << (*it).second << '\t'
|
||||
<< (*it).first << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue