- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
#include <fstream>
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <set>
#include <algorithm>
std::vector<std::string> split(const std::string &text, char sep) {
std::vector<std::string> tokens;
std::size_t start = 0, end = 0;
while ((end = text.find(sep, start)) != std::string::npos) {
std::string temp = text.substr(start, end - start);
if (temp != "") tokens.push_back(temp);
start = end + 1;
}
std::string temp = text.substr(start);
if (temp != "") tokens.push_back(temp);
return tokens;
}
void ReplaceStringInPlace(std::string& subject, const std::string& search,
const std::string& replace) {
size_t pos = 0;
while ((pos = subject.find(search, pos)) != std::string::npos) {
subject.replace(pos, search.length(), replace);
pos += replace.length();
}
}
using namespace std;
using std::vector;
using std::list;
using std::set;
int main()
{
setlocale(LC_ALL, "rus");
// задание 1
string buff;
list<string> allText;
//задание 2
list<string> chap1;
list<string> chap2;
list<string> chap3;
list<string> chap4;
list<string> chap5;
string::size_type n;
int chapter = 0;
//задание 5
vector<string> textWord;
vector<string> rezult;
vector <string>::size_type kolvotext=0;
set<string>Unique_word;
vector<string>::iterator j;
ifstream fin("D:\\lab_c__5_text.txt");
if (!fin.is_open())
cout << "Файл не может быть открыт!\n";
else {
while (getline(fin, buff)) {
allText.push_back(buff);
//разбиение по главам
n = buff.find("CHAPTER");
if (n == 0) {
chapter++;
}
if (chapter == 1) {
chap1.push_back(buff);
}
else if (chapter == 2) {
chap2.push_back(buff);
}
else if (chapter == 3) {
chap3.push_back(buff);
}
else if (chapter == 4) {
chap4.push_back(buff);
}
else if (chapter == 5) {
chap5.push_back(buff);
}
//разбиение по словам
ReplaceStringInPlace(buff, ".", "");
ReplaceStringInPlace(buff, "!", "");
ReplaceStringInPlace(buff, "?", "");
ReplaceStringInPlace(buff, ",", "");
ReplaceStringInPlace(buff, ";", "");
ReplaceStringInPlace(buff, ":", "");