Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <list>
- using namespace std;
- class Sortingoflist {
- public:
- static void sortinglist(list <string> &list1) {
- short counter = 0;
- string str1 = "", str2 = "", str3 = "", str4 = "", str5 = "";
- int mv1 = 0, mv2 = 0, mv3 = 0, mv4 = 0, mv5 = 0;
- for (string n : list1) {
- counter = 0;
- for (int j = 0; j < n.size(); j++) {
- if (n[j] >= '0' && n[j] <= '9') {
- ++counter;
- }
- }
- if (counter > mv1) {
- str5 = str4;
- mv5 = mv4;
- str4 = str3;
- mv4 = mv3;
- str3 = str2;
- mv3 = mv2;
- str2 = str1;
- mv2 = mv1;
- mv1 = counter;
- str1 = n;
- }
- else if (counter <= mv1 && counter > mv2) {
- str5 = str4;
- mv5 = mv4;
- str4 = str3;
- mv4 = mv3;
- str3 = str2;
- mv3 = mv2;
- mv2 = counter;
- str2 = n;
- }
- else if (counter <= mv2 && counter > mv3) {
- str5 = str4;
- mv5 = mv4;
- str4 = str3;
- mv4 = mv3;
- mv3 = counter;
- str3 = n;
- }
- else if (counter <= mv3 && counter > mv4) {
- str5 = str4;
- mv5 = mv4;
- mv4 = counter;
- str4 = n;
- }
- else if (counter <= mv4 && counter > mv5) {
- mv5 = counter;
- str5 = n;
- }
- }
- cout << str1 << " " << str2 << " " << str3 << " " << str4 << " " << str5 << endl;
- }
- };
- int main() {
- setlocale(LC_ALL, "Russian");
- ifstream fin("sorting.in");
- ofstream fout("sorting.out");
- if (!fin.is_open()) {
- fout << "Ошибка открытия файла!" << endl;
- }
- else if (fin.peek() == EOF) {
- fout << "Файл пуст!" << endl;
- }
- else {
- list <string> strings;
- string strforinput;
- while (fin.peek() != EOF) {
- getline(fin, strforinput, ',');
- strings.push_back(strforinput);
- }
- Sortingoflist::sortinglist(strings);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement