Дана строка текста.Между двумя точками упорядочить символы по возрастанию
Дана строка текста.. Известно, что в строке есть только две точки . Найти их порядковые номера. Далее упорядочить по возрастанию символы, расположенные между ними.
string s{ "The problem wasn't Dulce or his father.To discover and define those laws is the problem of history."};
size_t position = 0, position_1 = 0;
auto iter = search(s.cbegin(),s.cend(),".");
position = distance(s.cbegin(),iter);
position_1= distance(s.cbegin()+position,search(s.cbegin(),s.cend(),"."));
sort(s.cbegin() + position, s.cbegin()+position_1);
for (auto str : s)
{
cout << str;
}
cout << "\nFirst position:\t" << position << "\tSecond position:\t" << position_1 << endl;
Ответы (1 шт):
Автор решения: Mikhailo
→ Ссылка
int main() {
string s{ "The problem wasn't Dulce or his father.To "
"discover and define those laws is the problem "
"of history. Next sentence"};
size_t p1, p2;
p1 = s.find('.');
p2 = s.find('.', p1+1); // результат не проверяем -
// точки гарантированы условием
cout << "\nFirst position:\t" << p1
<< "\tSecond position:\t" << p2 <<
endl;
sort(s.begin() + p1 + 1, s.begin() + p2);
cout << s << endl;
}