Advertisement
Guest User

Atestat 37

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