Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <conio.h>
  4. #include <ctime>
  5. #include <bitset>
  6. #include <fstream>
  7. #include <stdlib.h>
  8. #include <cstring>
  9. #include <stdexcept>
  10. #include <random>
  11. #include <algorithm> //для сортировки
  12. using namespace std;
  13.  
  14. int main()
  15. {
  16. setlocale(0, "rus");
  17. ifstream fin("laba5.txt");
  18. string buff;
  19. vector <string> Array;
  20. int Count = 0; //Kol-vo slov
  21. cout << "Your words from File:" << endl;
  22. while (!fin.eof())
  23. {
  24. fin >> buff;
  25. Array.push_back(buff); //Помещаем слова из файла в вектор
  26.  
  27. cout << buff << endl;
  28. Count++;
  29. }
  30. string temp; // временная переменная для обмена элементов местами
  31.  
  32. // Сортировка массива пузырьком
  33. for (int i = 0; i < Count; i++) {
  34. for (int j = 0; j < Array[i].size(); j++) // внутренний цикл
  35. for (int k = 0; k<Array.size()-j-1;k++)
  36. {
  37. if (Array[i][j] > Array[i][j + 1]) // сравниваем два соседних элемента
  38. {
  39. // выполняем перестановку элементов массива
  40. temp[k] = Array[i][j];
  41. Array[i][j] = Array[i][j + 1];
  42. Array[i][j + 1] = temp[k];
  43. }
  44. }
  45. }
  46. cout << endl;
  47. cout << "Sort:" << endl;
  48. for (int i = 0; i < Count; i++)
  49.  
  50. {
  51. cout << Array[i] << " ";
  52. }
  53.  
  54.  
  55. cout << endl;
  56. fin.close();
  57. system("pause");
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement