nicuvlad76

Untitled

Jan 19th, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. char s[10001],sep[]=" .,";
  5. char cuv[101][101],*p,aux[101];
  6. int n;
  7. void Citire()
  8. {
  9. cin.getline(s, 10000);
  10. p=strtok(s,sep);
  11. while(p)
  12. {
  13. strcpy(cuv[++n],p);
  14. p=strtok(0,sep);
  15. }
  16. }
  17.  
  18. void Sortare()
  19. {
  20. bool ter=0;
  21. while(!ter)
  22. {
  23. ter=1;
  24. for(int i=1; i<n; i++)
  25. if(strcmp(cuv[i],cuv[i+1])>0)
  26. {
  27. strcpy(aux,cuv[i]);
  28. strcpy(cuv[i],cuv[i+1] );
  29. strcpy(cuv[i+1],aux);
  30. ter=0;
  31. }
  32. }
  33. }
  34. void Afisare()
  35. {
  36. for(int i=1; i<=n; i++)
  37. cout<<cuv[i]<<' ';
  38. }
  39. int main()
  40. {
  41. Citire();
  42. Sortare();
  43. Afisare();
  44. return 0;
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment