Advertisement
Dani_info

sortare alfabetica

Mar 24th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n;
  9.     char *aux;
  10.     cout<<"Cate nume se citesc?"; cin>>n;
  11.     char cuv[n][20];
  12.     for (int i=0; i<n; i++)
  13.         cin>>cuv[i];
  14.     int ok;
  15.     do{
  16.         ok=0;
  17.         for (int i=0; i<n-1; i++){
  18.             if (strcmp(cuv[i], cuv[i+1])<0){
  19.                 strcpy(aux,cuv[i]);
  20.                 strcpy(cuv[i],cuv[i+1]);
  21.                 strcpy(cuv[i+1],aux);
  22.                 ok=1;
  23.             }
  24.         }
  25.     }while(ok);
  26.  
  27.     cout<<endl<<endl;
  28.     for (int i=n; i>=0; i++){
  29.         cout<<cuv[i]<<" ";
  30.     cout<<endl;
  31.     }
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement