#include <cstdlib>
#include <iostream>
#include <string>
#include <locale>
#include <vector>
#include <algorithm>
using namespace std;
// Разделитель
const wchar_t DELIM = L'.';
typedef vector<wstring> str_vec;
// Разбивает строку по символу-разделителю, исключая пустые предложения
str_vec split(const wstring& str)
{
str_vec res;
wstring::const_iterator beg = str.begin(), end = str.end(), cur;
while ((cur = find(beg, end, DELIM)) != end)
{
if (cur != beg)
{
res.push_back(wstring(beg, cur));
}
beg = cur + 1;
}
return res;
}
int main()
{
locale::global(locale(""));
wstring str;
// Ввод строки
wcout << L"Введите строку:";
getline(wcin, str);
// Разбиваем строку по точкам
str_vec sv = split(str);
// Вывод результата
wcout << L"В строке: "" << str << L""" << L" предложений: " << sv.size() << endl;
for (str_vec::const_iterator it = sv.begin(), end = sv.end(); it != end; ++it)
{
wcout << L"Предложение:"" << *it << L"", знаков:" << it->length() << endl;
}
#ifdef _WIN32
system("pause");
#endif
return (EXIT_SUCCESS);
}
Введите строку:1-е предложение. А это второе. Наверное, хватит
В строке"1-е предложение. А это второе. Наверное, хватит" предложений: 3
Предложение:"1-е предложение", знаков:15
Предложение:" А это второе", знаков:13
Предложение:" Наверное, хватит", знаков:17
#include <cstdlib>
#include <iostream>
#include <string>
#include <locale>
#include <vector>
#include <algorithm>
using namespace std;
// Разделитель
const wchar_t DELIM = '.';
typedef vector<string> str_vec;
// Разбивает строку по символу-разделителю, исключая пустые предложения
str_vec split(const string& str)
{
str_vec res;
string::const_iterator beg = str.begin(), end = str.end(), cur;
while (beg != end)
{
cur = find(beg, end, DELIM);
if (cur != beg)
{
res.push_back(string(beg, cur));
}
beg = cur + (cur != end);
}
return res;
}
int main()
{
locale::global(locale(""));
string str;
// Ввод строки
cout << "Input string:";
getline(cin, str);
// Разбиваем строку по точкам
str_vec sv = split(str);
// Вывод результата
cout << "In string"" << str << """ << " sentenses: " << sv.size() << endl;
for (str_vec::const_iterator it = sv.begin(), end = sv.end(); it != end; ++it)
{
cout << """ << *it << "", characters:" << it->length() << endl;
}
#ifdef _WIN32
system("pause");
#endif
return (EXIT_SUCCESS);
}
#include <cstdlib>
#include <iostream>
#include <string>
#include <cstring>
#include <locale>
#include <vector>
#include <algorithm>
using namespace std;
// Разделитель
const wchar_t DELIM = '.';
typedef vector<string> str_vec;
// Разбивает строку по символу-разделителю, исключая пустые предложения
str_vec split(const string& str)
{
str_vec res;
string::const_iterator beg = str.begin(), end = str.end(), cur;
while (beg != end)
{
cur = find(beg, end, DELIM);
if (cur != beg)
{
res.push_back(string(beg, cur));
}
beg = cur + (cur != end);
}
return res;
}
size_t characters(const string& str)
{
size_t res=0;
for(string::const_iterator it = str.begin(), end = str.end(); it!=end; ++it)
{
res+=!isspace(*it);
}
return res;
}
int main()
{
locale::global(locale(""));
string str;
// Ввод строки
cout << "Input string:";
getline(cin, str);
// Разбиваем строку по точкам
str_vec sv = split(str);
// Вывод результата
cout << "In string"" << str << """ << " sentenses: " << sv.size() << endl;
for (str_vec::const_iterator it = sv.begin(), end = sv.end(); it != end; ++it)
{
cout << """ << *it << "", characters:" << characters(*it) << endl;
}
#ifdef _WIN32
system("pause");
#endif
return (EXIT_SUCCESS);
}
// Разбивает строку по символу-разделителю, исключая пустые предложения
str_vec split(const string& str)
{
str_vec res;
string::const_iterator beg = str.begin(), end = str.end(), cur;
while ((cur = find(beg, end, DELIM)) != end)
{
if (cur != beg)
{
res.push_back(string(beg, cur));
}
beg = cur + 1;
}
return res;
}
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.