Advertisement
Guest User

sortirovka v alphavitnom poryadke

a guest
Dec 14th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. setlocale(LC_ALL, "");
  9. srand(time(0));
  10.  
  11. string a;
  12. int i, j, number;
  13. char bukva;
  14.  
  15. for (i = 0; i < 30; i++) {
  16. number = 97 + rand() % 26;
  17. bukva = (char)number;
  18. a += bukva;
  19. }
  20. cout << "Исходный массив:\n";
  21. cout << a << endl;
  22.  
  23. for (i = 1; i < 30; i++) {
  24. for (j = 0; j < 29; j++) {
  25. if (a[i] < a[j]) {
  26. bukva = a[i];
  27. a[i] = a[j];
  28. a[j] = bukva;
  29. }
  30. }
  31. }
  32. cout << "Отсортированный массив:\n";
  33. cout << a << endl;
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement