Advertisement
Guest User

dlaAni

a guest
Mar 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3.  
  4. bool operator>(std::string lewy, std::string prawy) {
  5.  
  6. if (lewy.length() > prawy.length())
  7. return true;
  8. else if (lewy.length() == prawy.length()) {
  9. for (int i = 0; i < lewy.length(); ++i) {
  10. if (prawy[i] > lewy[i])
  11. return false;
  12. else if (lewy[i] > prawy[i])
  13. return true;
  14. else
  15. continue;
  16. }
  17. return false;
  18. }
  19. else
  20. return false;
  21. }
  22.  
  23. std::string sortuj(std::string* tablica, int elementy) {
  24. for (int i = 0; i < elementy-1; ++i) {
  25. bool flaga = false;
  26. for (int j = 0; j < elementy - 1 - i; ++j) {
  27. if (tablica[j] > tablica[j + 1]) {
  28. std::swap(tablica[j], tablica[j + 1]);
  29. flaga = true;
  30. }
  31. }
  32. if (flaga == false)
  33. return *tablica;
  34. }
  35. return *tablica;
  36. }
  37.  
  38. int main() {
  39.  
  40. int elementy = 0;
  41. while (std::cin >> elementy) {
  42.  
  43. std::string *tablica = new std::string[elementy];
  44.  
  45. for (int i = 0; i < elementy; ++i)
  46. std::cin >> tablica[i];
  47.  
  48. sortuj(tablica, elementy);
  49.  
  50. for (int i = 0; i < elementy; ++i)
  51. std::cout << tablica[i] << std::endl;
  52.  
  53. }
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement