#include <iostream>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <Windows.h>
using namespace std;
string cleanWord(string s) {
string r = "";
for (int i = 0; i < s.length(); i++) {
char c = s[i];
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
if (c >= 'A' && c <= 'Z') r += c + 32;
else r += c;
}
}
return r;
}
int main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
setlocale(LC_ALL, "rus");
ifstream file("24_3ada4a.txt");
if (!file.is_open()) {
cout << "Файл не найден" << endl;
return 1;
}
string text;
string line;
while (getline(file, line)) {
text += line + " ";
}
file.close();
cout << "Текст из файла: " << text << endl;
// Разбиваем на предложения
vector<string> predl;
string temp = "";
for (char c : text) {
temp += c;
if (c == '.' || c == '!' || c == '?') {
if (temp.length() > 1) {
predl.push_back(temp);
temp = "";
}
}
}
cout << "Предложений: " << predl.size() << endl << endl;
for (int i = 0; i < predl.size(); i++) {
cout << i + 1 << ": " << predl[i] << endl;
}
// Слова из первого предложения
vector<string> firstWords;
stringstream ss(predl[0]);
string word;
while (ss >> word) {
string clean = cleanWord(word);
if (!clean.empty()) {
bool already = false;
for (string w : firstWords) {
if (w == clean) {
already = true;
break;
}
}
if (!already) {
firstWords.push_back(clean);
}
}
}
// Общие слова
vector<string> commonWords;
for (string w : firstWords) {
bool inAll = true;
for (int j = 1; j < predl.size(); j++) {
stringstream ss2(predl[j]);
string word2;
bool found = false;
while (ss2 >> word2) {
string clean2 = cleanWord(word2);
if (clean2 == w) {
found = true;
break;
}
}
if (!found) {
inAll = false;
break;
}
}
if (inAll) {
commonWords.push_back(w);
}
}
// Результат
if (commonWords.empty()) {
cout << "Не нашлось одинаковых слов" << endl;
} else {
cout << "Слова встречающиеся в каждом предложении: " << endl;
for (string w : commonWords) {
cout << w << endl;
}
}
return 0;
}