Repository navigation
Expand file tree
/
Copy pathProga6-2.cpp
More file actions
59 lines (49 loc) · 1.63 KB
/
Copy pathProga6-2.cpp
File metadata and controls
59 lines (49 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
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
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
int countPunctuation(const std::string& sentence) {
int count = 0;
for (char c : sentence) {
if (c == '.' || c == ',' || c == '!' || c == '?' || c == ';' || c == ':' || c == '-') {
count++;
}
}
return count;
}
int main() {
std::ifstream inputFile("input.txt"); // ôàéë ñ èñõîäíûì òåêñòîì
if (!inputFile) {
std::cerr << "Íå óäàëîñü îòêðûòü ôàéë!" << std::endl;
return 1;
}
std::string line;
std::string fullText;
while (std::getline(inputFile, line)) {
fullText += line + "\n"; // Ñ÷èòûâàåì òåêñò ïîñòðî÷íî
}
inputFile.close();
std::stringstream iss(fullText);
std::string sentence;
int maxPunctuationCount = 0;
std::vector<std::string> sentencesWithMaxPunctuation;
while (std::getline(iss, sentence, '.')) { // Ðàçäåëÿåì ïðåäëîæåíèÿ ïî òî÷êå
if (sentence.empty()) {
continue;
}
int punctuationCount = countPunctuation(sentence);
if (punctuationCount > maxPunctuationCount) {
maxPunctuationCount = punctuationCount;
sentencesWithMaxPunctuation.clear();
sentencesWithMaxPunctuation.push_back(sentence);
}
else if (punctuationCount == maxPunctuationCount) {
sentencesWithMaxPunctuation.push_back(sentence);
}
}
for (const std::string& sent : sentencesWithMaxPunctuation) {
std::cout << sent << "." << std::endl; // Âûâîäèì ïðåäëîæåíèÿ
}
return 0;
}