Advertisement
a53

LungSortDesc

a53
Dec 1st, 2018
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. char s[256],cuv[256][256],*p,separator[]=" ";
  8. cin.get(s,256);
  9. p=s;
  10. p=strtok(p,separator);
  11. int n=0,LitD[256];
  12. while(p)
  13. strcpy(cuv[n],p),LitD[n]=strlen(cuv[n]),++n,p=strtok(NULL,separator);
  14. for(int i=0;i<n-1;++i)
  15. for(int j=i+1;j<n;++j)
  16. if(LitD[i]<=LitD[j])
  17. {
  18. if(LitD[i]==LitD[j])
  19. {
  20. if(strcmp(cuv[i],cuv[j])==1)
  21. swap(LitD[i],LitD[j]),swap(cuv[i],cuv[j]);
  22. }
  23. else
  24. swap(LitD[i],LitD[j]),swap(cuv[i],cuv[j]);
  25. }
  26. for(int i=0;i<n;++i)
  27. cout<<cuv[i]<<'\n';
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement