Advertisement
Guest User

Sort

a guest
Feb 26th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <list>
  5. using namespace std;
  6.  
  7. class Sortingoflist {
  8. public:
  9. static void sortinglist(list <string> &list1) {
  10. short counter = 0;
  11. string str1 = "", str2 = "", str3 = "", str4 = "", str5 = "";
  12. int mv1 = 0, mv2 = 0, mv3 = 0, mv4 = 0, mv5 = 0;
  13. for (string n : list1) {
  14. counter = 0;
  15. for (int j = 0; j < n.size(); j++) {
  16. if (n[j] >= '0' && n[j] <= '9') {
  17. ++counter;
  18. }
  19. }
  20. if (counter > mv1) {
  21. str5 = str4;
  22. mv5 = mv4;
  23. str4 = str3;
  24. mv4 = mv3;
  25. str3 = str2;
  26. mv3 = mv2;
  27. str2 = str1;
  28. mv2 = mv1;
  29. mv1 = counter;
  30. str1 = n;
  31. }
  32.  
  33. else if (counter <= mv1 && counter > mv2) {
  34. str5 = str4;
  35. mv5 = mv4;
  36. str4 = str3;
  37. mv4 = mv3;
  38. str3 = str2;
  39. mv3 = mv2;
  40. mv2 = counter;
  41. str2 = n;
  42. }
  43. else if (counter <= mv2 && counter > mv3) {
  44. str5 = str4;
  45. mv5 = mv4;
  46. str4 = str3;
  47. mv4 = mv3;
  48. mv3 = counter;
  49. str3 = n;
  50. }
  51. else if (counter <= mv3 && counter > mv4) {
  52. str5 = str4;
  53. mv5 = mv4;
  54. mv4 = counter;
  55. str4 = n;
  56. }
  57. else if (counter <= mv4 && counter > mv5) {
  58. mv5 = counter;
  59. str5 = n;
  60. }
  61. }
  62.  
  63. cout << str1 << " " << str2 << " " << str3 << " " << str4 << " " << str5 << endl;
  64. }
  65. };
  66.  
  67. int main() {
  68. setlocale(LC_ALL, "Russian");
  69.  
  70. ifstream fin("sorting.in");
  71. ofstream fout("sorting.out");
  72.  
  73. if (!fin.is_open()) {
  74. fout << "Ошибка открытия файла!" << endl;
  75. }
  76. else if (fin.peek() == EOF) {
  77. fout << "Файл пуст!" << endl;
  78. }
  79. else {
  80. list <string> strings;
  81. string strforinput;
  82. while (fin.peek() != EOF) {
  83. getline(fin, strforinput, ',');
  84. strings.push_back(strforinput);
  85. }
  86. Sortingoflist::sortinglist(strings);
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement