Advertisement
STANAANDREY

ordonare lex

Oct 8th, 2019
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <stdio.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     char text[256], s[256][256];
  9.     gets(text);
  10.  
  11.     char sep[] = " .,";
  12.     char *p = strtok(text, sep);
  13.     int k = 0;
  14.     while (p)
  15.     {
  16.         strcpy(s[k], p);
  17.         k++;
  18.         p = strtok(NULL, sep);
  19.     }
  20.  
  21.     for (int i = 0; i < k - 1; i++)
  22.         for (int j = i + 1; j < k; j++)
  23.             if (strcmp(s[i], s[j]) > 0)
  24.         {
  25.             char aux[256];
  26.             strcpy(aux, s[i]);
  27.             strcpy(s[i], s[j]);
  28.             strcpy(s[j], aux);
  29.         }
  30.  
  31.         for (int i = 0; i < k; i++)
  32.             cout << s[i] << endl;
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement