Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- typedef vector<string> tab;
- void minuscule(tab& x);
- void affiche(tab x);
- void tri_alphabetique(tab& x);
- int main()
- {
- tab banana;
- banana.push_back("Michel");
- banana.push_back("Jacky");
- banana.push_back("Adeline");
- banana.push_back("MARIUS");
- minuscule(banana);
- tri_alphabetique(banana);
- affiche(banana);
- return 0;
- }
- void tri_alphabetique(tab& x)
- {
- bool ok(false);
- int z(0);
- string tampon;//permet de classer les mot par ordre alphabetique mais celement de la première lettre
- do
- {
- ok=false;
- for(size_t i(0); i<x.size()-1; i++)
- {
- if(x[i][0]>x[i+1][0])
- {
- tampon=x[i];
- x[i]=x[i+1];
- x[i+1]=tampon;
- ok=true;
- }
- }
- }
- while(ok);
- do//refait la même chose qu'au desus
- {
- ok=false;
- for(size_t i(0); i<x.size()-1; i++)
- {
- if(x[i][z]==x[i+1][z])//si il y a 2 mot avec la meme première lettre il vas tester la 2ème lettre après et si elle sont identique il vas encore ésayller jusqu'a trouver unelettre avant l'autre
- {
- ok=true;
- z++;
- if(x[i][z]>x[i+1][z])
- {
- tampon=x[i];
- x[i]=x[i+1];
- x[i+1]=tampon;
- }
- }
- }
- }while(ok);
- }
- void minuscule(tab& x) //passe toute les lettres en minuscule
- {
- for(size_t j(0); j<x.size(); j++)
- {
- for(size_t i(0); i<x[j].size(); i++)
- {
- if(x[j][i]>='A' and x[j][i]<='Z')
- {
- x[j][i]=x[j][i]+32;
- }
- }
- }
- }
- void affiche(tab x)
- {
- for(size_t j(0); j<x.size(); j++)
- {
- cout<<x[j]<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement