Advertisement
Guest User

Untitled

a guest
May 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8.  
  9. int main()
  10. {
  11.     ofstream fout;
  12.     string path;
  13.     cout << "Enter file name" << endl;
  14.     cin >> path;
  15.     fout.open(path, ofstream::app);
  16.    
  17.     //// обработка файла
  18.  
  19.     vector<string> lines;
  20.     fout.close();
  21.     ifstream fin;
  22.     fin.open(path, ifstream::app);
  23.     int N, M;
  24.     fin >> N >> M;
  25.     int filelen = 0;
  26.     string trash;
  27.     getline(fin, trash);
  28.     while (filelen < N)
  29.     {  
  30.         string line = " ";
  31.         getline(fin, line);
  32.         lines.push_back(line);
  33.         filelen++;
  34.     };
  35.  
  36.     // сортировка
  37.  
  38.     vector<string> newlines;
  39.     for (int k = 0; k < N; k++) {
  40.         for (int i = 0; i < N; i++)
  41.         {
  42.             if (i == N - 1)
  43.             {
  44.                 break;
  45.             }                                    //сортировка по алфавиту ( плохая:) )
  46.             if (lines[i] > lines[i + 1])
  47.             {
  48.                 string a;
  49.                 a = lines[i];
  50.                 lines[i] = lines[i + 1];
  51.                 lines[i + 1] = a;
  52.             }
  53.         }
  54.     }
  55.    
  56.    
  57.     for (int i = 0; i < lines.size(); i++)
  58.     {
  59.         string dots = ".";
  60.         if (lines[i].size() < M)
  61.         {
  62.             int amount_dots = M - lines[i].size();             //дополнение точками
  63.             for (int i = 0; i < amount_dots-1; i++)
  64.             {
  65.                 dots += ".";
  66.             }
  67.             lines[i] = lines[i] + dots;
  68.         }
  69.     }
  70.  
  71.     for (auto x : lines)
  72.     {
  73.         cout << x << endl;
  74.     }
  75.    
  76.     fout.open("B.txt");
  77.     for (auto x : lines)
  78.     {
  79.         fout << x << endl;
  80.     }
  81.     fout.close();
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement