работает почему-то только с первым словом, остальные почему-то игнорит
for (int i = 0; i < 1000; i++)
{
if(text[i] == ' ' || text[i] == ',' || text[i] == '.' || text[i] == '!' || text[i] == '?' || text[i] == '\n')
{ }
for (int j = i+1; j < 1000; j++)
{
if (isalpha(text[i]) && isalpha(text[j]) && text[i] == text[j] &&(text[j + 1]==' '|| text[j + 1] == ','|| text[j + 1] == '.' || text[j + 1] == '!' || text[j + 1] == '?' || text[j + 1] == '\n'))
{
text[i] = toupper(text[i]);
text[j] = toupper(text[j]);
i = i + j;
break;
}
if(text[j + 1] == ' ' || text[j + 1] == ',' || text[j + 1] == '.' || text[j + 1] == '!' || text[j + 1] == '?' || text[j + 1] == '\n')
{
i = i + j; break;
}
}
}
Другие языки программирования и технологии
c++ в словах, которые начинаются и заканчиваются одной и той же буквой, послед и первая буква должны стать большими
Парсинг слов в предложении - сто раз решенная задача, для нее пишется конечный автомат или же используется istringstream.
А не такое спагетти, как тут (( С таким ужасом C++ не осилить, НИЧЕГО работать не будет.
А не такое спагетти, как тут (( С таким ужасом C++ не осилить, НИЧЕГО работать не будет.
#include < iostream>
#include < vector>
#include < string>
int main() {
std::vector< std::string> words {"", "abc", "aba"};
for (auto& word: words) {
if (word.empty()) { continue; }
auto& f = word.front();
auto& b = word.back();
if (f == b && std::isalpha(f)) {
f = std::toupper(f);
b = f;
}
}
for (auto&& i : words)
std::cout < < i < < "\n";
}
#include < vector>
#include < string>
int main() {
std::vector< std::string> words {"", "abc", "aba"};
for (auto& word: words) {
if (word.empty()) { continue; }
auto& f = word.front();
auto& b = word.back();
if (f == b && std::isalpha(f)) {
f = std::toupper(f);
b = f;
}
}
for (auto&& i : words)
std::cout < < i < < "\n";
}
http://coliru.stacked-crooked.com/a/fbfaccf151c9282b
#include <algorithm>
#include <iostream>
#include <regex>
#include <string>
auto main() -> int
{
std::regex re{R"~([/.,\s]+)~"};
std::string str = "A fishman brought a fishf. fish fishman fishers. lol. abracadabra saasj sa bacb ";
std::sregex_token_iterator begin{std::begin( str ), std::end( str ), re, -1}, end;
std::for_each( begin, end, [&str]( const std::ssub_match & match ) {
auto first = std::distance( std::cbegin( str ), match.first );
auto last = std::distance( std::cbegin( str ), match.second );
if ( first != last && (--last, str[first] == str[last]) )
str[first] = str[last] = std::toupper( *match.first );
} );
std::cout << str << std::endl;
return 0;
}
#include <algorithm>
#include <iostream>
#include <regex>
#include <string>
auto main() -> int
{
std::regex re{R"~([/.,\s]+)~"};
std::string str = "A fishman brought a fishf. fish fishman fishers. lol. abracadabra saasj sa bacb ";
std::sregex_token_iterator begin{std::begin( str ), std::end( str ), re, -1}, end;
std::for_each( begin, end, [&str]( const std::ssub_match & match ) {
auto first = std::distance( std::cbegin( str ), match.first );
auto last = std::distance( std::cbegin( str ), match.second );
if ( first != last && (--last, str[first] == str[last]) )
str[first] = str[last] = std::toupper( *match.first );
} );
std::cout << str << std::endl;
return 0;
}
самыми простыми свойствами языка
https://pastebin.com/2L1c0Ksa
https://pastebin.com/2L1c0Ksa
Похожие вопросы
- Нужна функция на php которая будет считывать текст из файла и выводить слова которые начинаются и заканчиваются на "а"
- C# Парсинг слов из строки без регистра
- C++(консоль) Программа, которая выводит данные треугольников со стороной максимум 5000
- Найти трехзначные числа a, b, c, все цифры которых различны и удовлетворяют уравнению a^2 – b^2 – c^2 = a – b – c.
- Программа C++ Напишите программу которая переводит из десятичной в двоичную систему счисления (C++)
- C# Сделать программу которая разделяет текст на предложения.
- самое короткое слово которое что либо обозначает кроме слова я
- Написать программу в С++ В тексте Найти слово, которое встречается в тексте максимальное количество раз.
- найти первую букву второго слова в строке. c++
- Как сделать программу которая при вводе текста, удаляет из текста все слова, содержащие букву «я». (PascalABC)
И еще видно, что over-complicated, если f == b, а f - буква, то зачем b то проверять.