Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. char s[257],t[257][257],*p,c[257];
  5. int k=1;
  6. void citire()
  7. { cin.get(s,256);
  8. p=strtok(s," ");
  9. while(p!=NULL)
  10. { strcpy(t[k],p);
  11. k++;
  12. p=strtok(NULL," ");
  13. }
  14. int ok=0,i,x,y;
  15. k--;
  16. do
  17. {ok=1;
  18. for(i=1;i<=k-1;i++)
  19. { x=strlen(t[i]);
  20. y=strlen(t[i+1]);
  21. if(x<y)
  22. { ok=0;
  23. strcpy(c,t[i]);
  24. strcpy(t[i],t[i+1]);
  25. t[i][y+1]=NULL;
  26. strcpy(t[i+1],c);
  27. t[i+1][x+1]=NULL;
  28. c[0]=NULL;
  29. }
  30. else
  31. { if(x==y)
  32. { if(strcmp(t[i],t[i+1])>0)
  33. {ok=0;
  34. strcpy(c,t[i]);
  35. strcpy(t[i],t[i+1]);
  36. t[i][y+1]=NULL;
  37. strcpy(t[i+1],c);
  38. t[i+1][x+1]=NULL;
  39. c[0]=NULL;
  40.  
  41. }
  42. }
  43. }
  44.  
  45. }
  46.  
  47. }while(ok==0);
  48. for(i=1;i<=k;i++)
  49. cout<<t[i]<<endl;
  50. }
  51. int main()
  52. {
  53. citire();
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement