#include <iostream>
#include <regex>
using std::cout;
using std::endl;
using std::pair;
using std::regex;
using std::vector;
using std::string;
using std::smatch;
using std::regex_match;
typedef vector<pair<string,int>> ResType;
void WordsCount(string T, ResType &Res) {
smatch Matches;
regex RegexpDot("^.*?(.+?)\\.\\s*(.*)$");
regex RegexpWord("^.*?([a-zA-Z]+)\\s*(.*)$");
vector<string> Lines;
while(regex_match(T, Matches, RegexpDot)) { Lines.push_back(Matches[1]); T=Matches[2]; }
for(const auto &i:Lines) {
int N = 0;
string Tmp = i;
while(regex_match(Tmp, Matches, RegexpWord)) { Tmp=Matches[2]; N++; }
Res.push_back({i,N});
}
}
int main() {
try {
ResType Res;
string Text = "mama mila ramu. Rama vusmert' zadolbala mamu. 128 raz.";
WordsCount(Text,Res);
for(const auto &i:Res) cout << "\"" << i.first << "\": " << i.second << endl;
} catch (std::regex_error& Err) {
std::cout << "Засада: " << Err.what();
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8cmVnZXg+Cgp1c2luZyBzdGQ6OmNvdXQ7CnVzaW5nIHN0ZDo6ZW5kbDsKdXNpbmcgc3RkOjpwYWlyOyAgICAKdXNpbmcgc3RkOjpyZWdleDsKdXNpbmcgc3RkOjp2ZWN0b3I7CnVzaW5nIHN0ZDo6c3RyaW5nOwp1c2luZyBzdGQ6OnNtYXRjaDsKdXNpbmcgc3RkOjpyZWdleF9tYXRjaDsKCnR5cGVkZWYgdmVjdG9yPHBhaXI8c3RyaW5nLGludD4+IFJlc1R5cGU7Cgp2b2lkIFdvcmRzQ291bnQoc3RyaW5nIFQsIFJlc1R5cGUgJlJlcykgewogIHNtYXRjaCBNYXRjaGVzOwogIHJlZ2V4IFJlZ2V4cERvdCgiXi4qPyguKz8pXFwuXFxzKiguKikkIik7IAogIHJlZ2V4IFJlZ2V4cFdvcmQoIl4uKj8oW2EtekEtWl0rKVxccyooLiopJCIpOyAgICAgCiAgdmVjdG9yPHN0cmluZz4gTGluZXM7ICAK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