Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "TM.h"
- #include "Input.h"
- #include "Output.h"
- #include "Process.h"
- #include "Clean.h"
- using namespace std;
- int unsigned max = 100;
- int main()
- {
- TM Text;
- input(Text, max);
- output(Text, 1);
- Process(Text);
- output(Text, 2);
- //Clean(Text);
- delete Text.Txt;
- return 0;
- }
- void input(TM &Text, int max)
- {
- fstream f;
- f.open("Text.txt", ios::in);
- int count = 0;
- bool ok = false;
- streampos p;
- char c;
- f.unsetf(ios::skipws);
- while (1)
- {
- f >> c;
- if (f.eof() == true)
- break;
- count++;
- while ((c != '\n') && (f.eof() == false))
- f >> c;
- }
- if (max != 0)
- {
- Text.L = count;
- Text.Txt = new Str[Text.L];
- }
- else
- {
- Text.Txt = new Str[1];
- Text.L = 1;
- }
- count = 0;
- f.clear();
- f.seekg(0);
- for (int i = 0; i < Text.L; i++)
- {
- p = f.tellg();
- do
- {
- f >> c;
- if (f.eof() == true)
- break;
- count++;
- if (count >= max)
- {
- if(c != '\n')
- ok = true;
- count = max;
- break;
- }
- } while (c != '\n');
- if(ok == false)
- Text.Txt[i].S = new char[count + 1];
- else
- Text.Txt[i].S = new char[count + 2];
- f.clear();
- f.seekg(p);
- for (int j = 0; j < count; j++)
- f >> Text.Txt[i].S[j];
- if(ok == false)
- Text.Txt[i].S[count] = Text.Txt[i].mark;
- else
- {
- Text.Txt[i].S[count + 1] = Text.Txt[i].mark;
- Text.Txt[i].S[count] = '\n';
- }
- count = 0;
- if (ok == true)
- {
- while ((c != '\n') && (!f.eof()))
- {
- f >> c;
- }
- }
- ok = false;
- }
- f.close();
- }
- void output(TM &Text, int a)
- {
- fstream f;
- if (a == 1)
- {
- f.open("Out.txt", ios::out);
- f << "Исходный текст:\n";
- for (int i = 0; i < Text.L; i++)
- {
- for (int j = 0; Text.Txt[i].S[j] != Text.Txt[i].mark; j++)
- {
- f << Text.Txt[i].S[j];
- }
- }
- f << endl << endl;
- }
- else
- {
- f.open("Out.txt", ios::app);
- int p = 0, q = 0, e = 0;
- bool l = false, s = false, t = false;
- for (int i = 0; i < Text.L; i++)
- {
- for (int j = 0; Text.Txt[i].S[j] != Text.Txt[i].mark; j++)
- {
- if (Text.Txt[i].S[j] == '.')
- p++;
- else if (Text.Txt[i].S[j] == '?')
- q++;
- else if (Text.Txt[i].S[j] == '!')
- e++;
- }
- }
- f << "Модифицированный текст:\n";
- for (int i = 0; i < Text.L; i++)
- {
- if (i < p)
- {
- if (l == false)
- {
- f << "Повествовательные предложения:\n";
- l = true;
- }
- f << i + 1 << '.' << ' ';
- }
- else if ((i >= p) && (i < q + p))
- {
- if (s == false)
- {
- f << "Вопросительные предложения:\n";
- s = true;
- }
- f << i + 1 - p << '.' << ' ';
- }
- else if ((i < e + p + q) && (i >= q + p))
- {
- if (t == false)
- {
- f << "Восклицательные предложения:\n";
- t = true;
- }
- f << i + 1 - q - p << '.' << ' ';
- }
- for (int j = 0; Text.Txt[i].S[j] != Text.Txt[i].mark; j++)
- {
- if ((Text.Txt[i].S[j] == ' ') && (j == 0))
- continue;
- if((Text.Txt[i].S[j] != ' ') || (Text.Txt[i].S[j + 1] != ' '))
- f << Text.Txt[i].S[j];
- }
- f << endl;
- }
- }
- f.close();
- }
- void Process(TM &Text)
- {
- TM NewText;
- int point = 0, question = 0, exclamation = 0, pos1 = 0, pos2 = 0, n = 0, count = 0, k = 0, l = 0;
- bool pr = false;
- for (int i = 0; i < Text.L; i++)
- {
- for (int j = 0; Text.Txt[i].S[j] != Text.Txt->mark; j++)
- {
- if (Text.Txt[i].S[j] == '.')
- point++;
- else if (Text.Txt[i].S[j] == '!')
- exclamation++;
- else if (Text.Txt[i].S[j] == '?')
- question++;
- }
- }
- NewText.L = point + question + exclamation;
- NewText.Txt = new Str[NewText.L];
- exclamation = question + point;
- question = point;
- point = 0;
- Str temp;
- for (int i = 0; i < Text.L; i++)
- {
- for (int j = 0; Text.Txt[i].S[j] != Text.Txt[i].mark; j++)
- {
- if (pr == false)
- {
- pos1 = i; pos2 = j;
- pr = true;
- }
- //if(Text.Txt[i].S[j] != '\n')
- count++;
- if ((Text.Txt[i].S[j] == '.') || (Text.Txt[i].S[j] == '!') || (Text.Txt[i].S[j] == '?'))
- {
- temp.S = new char[count + 1];
- for (k = pos1; k < Text.L; k++)
- {
- for (l = pos2; Text.Txt[k].S[l] != Text.Txt->mark; l++)
- {
- if (Text.Txt[k].S[l] != '\n')
- {
- temp.S[n] = Text.Txt[k].S[l];
- n++;
- pos1++;
- pos2 = 0;
- }
- else
- {
- temp.S[n] = ' ';
- n++;
- }
- if ((Text.Txt[k].S[l] == '.') || (Text.Txt[k].S[l] == '?') || (Text.Txt[k].S[l] == '!') || (n >= count))
- break;
- }
- if (n >= count)
- break;
- }
- temp.S[count] = '\n';
- if (Text.Txt[k].S[l] == '.')
- {
- NewText.Txt[point].S = new char[n + 1];
- for (int m = 0; m < n; m++)
- NewText.Txt[point].S[m] = temp.S[m];
- NewText.Txt[point].S[n] = NewText.Txt->mark;
- point++;
- }
- else if (Text.Txt[k].S[l] == '?')
- {
- NewText.Txt[question].S = new char[n + 1];
- for (int m = 0; m < n; m++)
- NewText.Txt[question].S[m] = temp.S[m];
- NewText.Txt[question].S[n] = NewText.Txt->mark;
- question++;
- }
- else if (Text.Txt[k].S[l] == '!')
- {
- NewText.Txt[exclamation].S = new char[n + 1];
- for (int m = 0; m < n; m++)
- NewText.Txt[exclamation].S[m] = temp.S[m];
- NewText.Txt[exclamation].S[n] = NewText.Txt->mark;
- exclamation++;
- }
- n = 0;
- delete[] temp.S;
- count = 0;
- pr = false;
- if ((Text.Txt[i].S[j + 1] == '\n') || (Text.Txt[i].S[j + 1] == ' '))
- j++;
- }
- }
- }
- delete[] Text.Txt;
- Text.Txt = NewText.Txt;
- Text.L = NewText.L;
- //delete NewText.Txt;
- }
- #pragma once
- struct Str
- {
- char *S;
- char mark = '#';
- //~Str() { delete[] S; }
- };
- #pragma once
- #include "Str.h"
- struct TM
- {
- Str *Txt;
- int unsigned L;
- // ~TM() { Txt->~Str(); }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement