Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.80 KB | None | 0 0
  1. #include <iostream>
  2. #include "TM.h"
  3. #include "Input.h"
  4. #include "Output.h"
  5. #include "Process.h"
  6. #include "Clean.h"
  7. using namespace std;
  8.  
  9. int unsigned max = 100;
  10.  
  11. int main()
  12. {
  13.     TM Text;
  14.     input(Text, max);
  15.     output(Text, 1);
  16.     Process(Text);
  17.     output(Text, 2);
  18.     //Clean(Text);
  19.     delete Text.Txt;
  20.     return 0;
  21. }
  22.  
  23. void input(TM &Text, int max)
  24. {
  25.     fstream f;
  26.     f.open("Text.txt", ios::in);
  27.     int count = 0;
  28.     bool ok = false;
  29.     streampos p;
  30.     char c;
  31.     f.unsetf(ios::skipws);
  32.     while (1)
  33.     {
  34.         f >> c;
  35.         if (f.eof() == true)
  36.             break;
  37.         count++;
  38.         while ((c != '\n') && (f.eof() == false))
  39.             f >> c;
  40.     }
  41.     if (max != 0)
  42.     {
  43.         Text.L = count;
  44.         Text.Txt = new Str[Text.L];
  45.     }
  46.     else
  47.     {
  48.         Text.Txt = new Str[1];
  49.         Text.L = 1;
  50.     }
  51.     count = 0;
  52.     f.clear();
  53.     f.seekg(0);
  54.     for (int i = 0; i < Text.L; i++)
  55.     {
  56.         p = f.tellg();
  57.         do
  58.         {
  59.             f >> c;
  60.             if (f.eof() == true)
  61.                 break;
  62.             count++;
  63.             if (count >= max)
  64.             {
  65.                 if(c != '\n')
  66.                     ok = true;
  67.                 count = max;
  68.                 break;
  69.             }
  70.         } while (c != '\n');
  71.         if(ok == false)
  72.             Text.Txt[i].S = new char[count + 1];
  73.         else
  74.             Text.Txt[i].S = new char[count + 2];
  75.         f.clear();
  76.         f.seekg(p);
  77.         for (int j = 0; j < count; j++)
  78.             f >> Text.Txt[i].S[j];
  79.         if(ok == false)
  80.             Text.Txt[i].S[count] = Text.Txt[i].mark;
  81.         else
  82.         {
  83.             Text.Txt[i].S[count + 1] = Text.Txt[i].mark;
  84.             Text.Txt[i].S[count] = '\n';
  85.         }
  86.         count = 0;
  87.         if (ok == true)
  88.         {
  89.             while ((c != '\n') && (!f.eof()))
  90.             {
  91.                 f >> c;
  92.             }
  93.         }
  94.         ok = false;
  95.     }
  96.     f.close();
  97. }
  98.  
  99. void output(TM &Text, int a)
  100. {
  101.     fstream f;
  102.     if (a == 1)
  103.     {
  104.         f.open("Out.txt", ios::out);
  105.         f << "Исходный текст:\n";
  106.         for (int i = 0; i < Text.L; i++)
  107.         {
  108.             for (int j = 0; Text.Txt[i].S[j] != Text.Txt[i].mark; j++)
  109.             {
  110.                 f << Text.Txt[i].S[j];
  111.             }
  112.         }
  113.         f << endl << endl;
  114.     }
  115.     else
  116.     {
  117.         f.open("Out.txt", ios::app);
  118.         int p = 0, q = 0, e = 0;
  119.         bool l = false, s = false, t = false;
  120.         for (int i = 0; i < Text.L; i++)
  121.         {
  122.             for (int j = 0; Text.Txt[i].S[j] != Text.Txt[i].mark; j++)
  123.             {
  124.                 if (Text.Txt[i].S[j] == '.')
  125.                     p++;
  126.                 else if (Text.Txt[i].S[j] == '?')
  127.                     q++;
  128.                 else if (Text.Txt[i].S[j] == '!')
  129.                     e++;
  130.             }
  131.         }
  132.         f << "Модифицированный текст:\n";
  133.         for (int i = 0; i < Text.L; i++)
  134.         {
  135.             if (i < p)
  136.             {
  137.                 if (l == false)
  138.                 {
  139.                     f << "Повествовательные предложения:\n";
  140.                     l = true;
  141.                 }
  142.                 f << i + 1 << '.' << ' ';
  143.             }
  144.             else if ((i >= p) && (i < q + p))
  145.             {
  146.                 if (s == false)
  147.                 {
  148.                     f << "Вопросительные предложения:\n";
  149.                     s = true;
  150.                 }
  151.                 f << i + 1 - p << '.' << ' ';
  152.             }
  153.             else if ((i < e + p + q) && (i >= q + p))
  154.             {
  155.                 if (t == false)
  156.                 {
  157.                     f << "Восклицательные предложения:\n";
  158.                     t = true;
  159.                 }
  160.                 f << i + 1 - q - p << '.' << ' ';
  161.             }
  162.             for (int j = 0; Text.Txt[i].S[j] != Text.Txt[i].mark; j++)
  163.             {
  164.                 if ((Text.Txt[i].S[j] == ' ') && (j == 0))
  165.                     continue;
  166.                 if((Text.Txt[i].S[j] != ' ') || (Text.Txt[i].S[j + 1] != ' '))
  167.                     f << Text.Txt[i].S[j];
  168.             }
  169.         f << endl;
  170.         }
  171.     }
  172.     f.close();
  173. }
  174.  
  175. void Process(TM &Text)
  176. {
  177.     TM NewText;
  178.     int point = 0, question = 0, exclamation = 0, pos1 = 0, pos2 = 0, n = 0, count = 0, k = 0, l = 0;
  179.     bool pr = false;
  180.     for (int i = 0; i < Text.L; i++)
  181.     {
  182.         for (int j = 0; Text.Txt[i].S[j] != Text.Txt->mark; j++)
  183.         {
  184.             if (Text.Txt[i].S[j] == '.')
  185.                 point++;
  186.             else if (Text.Txt[i].S[j] == '!')
  187.                 exclamation++;
  188.             else if (Text.Txt[i].S[j] == '?')
  189.                 question++;
  190.         }
  191.     }
  192.     NewText.L = point + question + exclamation;
  193.     NewText.Txt = new Str[NewText.L];
  194.     exclamation = question + point;
  195.     question = point;
  196.     point = 0;
  197.     Str temp;
  198.     for (int i = 0; i < Text.L; i++)
  199.     {
  200.         for (int j = 0; Text.Txt[i].S[j] != Text.Txt[i].mark; j++)
  201.         {
  202.             if (pr == false)
  203.             {
  204.                 pos1 = i; pos2 = j;
  205.                 pr = true;
  206.             }
  207.             //if(Text.Txt[i].S[j] != '\n')
  208.                 count++;
  209.             if ((Text.Txt[i].S[j] == '.') || (Text.Txt[i].S[j] == '!') || (Text.Txt[i].S[j] == '?'))
  210.             {
  211.                 temp.S = new char[count + 1];
  212.                 for (k = pos1; k < Text.L; k++)
  213.                 {
  214.                     for (l = pos2; Text.Txt[k].S[l] != Text.Txt->mark; l++)
  215.                     {
  216.                         if (Text.Txt[k].S[l] != '\n')
  217.                         {
  218.                             temp.S[n] = Text.Txt[k].S[l];
  219.                             n++;
  220.                             pos1++;
  221.                             pos2 = 0;
  222.                         }
  223.                         else
  224.                         {
  225.                             temp.S[n] = ' ';
  226.                             n++;
  227.                         }
  228.                         if ((Text.Txt[k].S[l] == '.') || (Text.Txt[k].S[l] == '?') || (Text.Txt[k].S[l] == '!') || (n >= count))
  229.                             break;
  230.                     }
  231.                     if (n >= count)
  232.                         break;
  233.                 }
  234.                 temp.S[count] = '\n';
  235.                 if (Text.Txt[k].S[l] == '.')
  236.                 {
  237.                     NewText.Txt[point].S = new char[n + 1];
  238.                     for (int m = 0; m < n; m++)
  239.                         NewText.Txt[point].S[m] = temp.S[m];
  240.                     NewText.Txt[point].S[n] = NewText.Txt->mark;
  241.                     point++;
  242.                 }
  243.                 else if (Text.Txt[k].S[l] == '?')
  244.                 {
  245.                     NewText.Txt[question].S = new char[n + 1];
  246.                     for (int m = 0; m < n; m++)
  247.                         NewText.Txt[question].S[m] = temp.S[m];
  248.                     NewText.Txt[question].S[n] = NewText.Txt->mark;
  249.                     question++;
  250.                 }
  251.                 else if (Text.Txt[k].S[l] == '!')
  252.                 {
  253.                     NewText.Txt[exclamation].S = new char[n + 1];
  254.                     for (int m = 0; m < n; m++)
  255.                         NewText.Txt[exclamation].S[m] = temp.S[m];
  256.                     NewText.Txt[exclamation].S[n] = NewText.Txt->mark;
  257.                     exclamation++;
  258.                 }
  259.                 n = 0;
  260.                 delete[] temp.S;
  261.                 count = 0;
  262.                 pr = false;
  263.                 if ((Text.Txt[i].S[j + 1] == '\n') || (Text.Txt[i].S[j + 1] == ' '))
  264.                     j++;
  265.             }
  266.         }
  267.     }
  268.     delete[] Text.Txt;
  269.     Text.Txt = NewText.Txt;
  270.     Text.L = NewText.L;
  271.     //delete NewText.Txt;
  272. }
  273.  
  274. #pragma once
  275. struct Str
  276. {
  277.     char *S;
  278.     char mark = '#';
  279.     //~Str() { delete[] S; }
  280. };
  281.  
  282. #pragma once
  283. #include "Str.h"
  284. struct TM
  285. {
  286.     Str *Txt;
  287.     int unsigned L;
  288. //  ~TM() { Txt->~Str(); }
  289. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement