Advertisement
Mastercpp

Untitled

Aug 3rd, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5. using namespace std;
  6.  
  7.  
  8. int main(){
  9.    
  10.     int longitud_arreglo; //Esta variables almacenar la cantidad de elementos que va a tener nuestro array
  11.     cout << "Cuantos nombres desea ingresar ? "; // le pido al usuario que ingrese el numero de nombre que va a ingresar
  12.     cin>>longitud_arreglo;
  13.    
  14.     string nombre[longitud_arreglo]; // aqui creamo un array de tipo string que tendra el numeros elementos que el valor que tenga longitud_arreglo
  15.     for(int i =0; i<longitud_arreglo; i++){
  16.         cout << "El ingrese el nombre numero " << i <<" : " << endl;
  17.         cin >> nombre[i];
  18.     }
  19.    
  20.    
  21.     vector<string>lista_de_nombres(nombre , nombre+longitud_arreglo);  
  22.    
  23.     sort(lista_de_nombres.begin(), lista_de_nombres.end()); // aqui es que ordenamos los vectores
  24.    
  25.     cout << "nombres ordenados en orden alfabetico " << endl;
  26.     //primera opcion para mostrar los vectores
  27.     for(vector<string>::iterator it = lista_de_nombres.begin(); it != lista_de_nombres.end(); it++ ){
  28.         cout << *it << endl;
  29.     }
  30.    
  31. //si quieres mostrar mas rapido haz esto
  32. /*
  33. for(int i =0; i<longitud_arreglo;  i++){
  34.     cout << lista_de_nombres [i] << endl;
  35. }  
  36. */ 
  37.     system("pause");
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement