Дана последовательность, содержащая от 2 до 50 слов, в каждом из которых от 1 до 8 строчных латинских букв; между соседними словами - не менее одного пробела, за последним словом - точка. Напечатать те слова последовательности, которые отличны от последнего слова и удовлетворяют следующему свойству: слово совпадает с начальным отрезком латинского алфавита (a, ab, abc, и т. д.); учесть, что в диапазоне 'a'..'z' могут быть литеры, отличные от латинских букв;
P.S.
Нашел ответы по условию задачи в сети, но они на Pascal, а я его не знаю.
Другие языки программирования и технологии
Помогите решить задачу на C или C++, пожалуйста.
Очень смешное условие, ибо оно означает, что слово просто должно начинаться на букву a.
Вот код:
#include <iostream>
#include <string>
#include <sstream>
#include <cctype>
#include <vector>
#include <algorithm>
int main(){
//Считываем все до точки
std::string in;
std::vector<std::string> words;
std::getline(std::cin, in, '.');
//Убираем знаки препинания
in.erase(std::remove_if(in.begin(), in.end(), ispunct), in.end());
//Создаем массив со словами
{
std::istringstream ss(in);
while(ss >> in)
words.push_back(in);
}
//Удаляем не подходящие слова
words.erase(std::remove_if(words.begin(), words.end(), [lastword = words.back()](const std::string& s){
return !(s.size() > 0 && *s.begin() == 'a' && s != lastword);
}), words.end());
//Выводим их на экран
for(const std::string& word : words){
std::cout << word << std::endl;
}
return 0;
}
Вот код:
#include <iostream>
#include <string>
#include <sstream>
#include <cctype>
#include <vector>
#include <algorithm>
int main(){
//Считываем все до точки
std::string in;
std::vector<std::string> words;
std::getline(std::cin, in, '.');
//Убираем знаки препинания
in.erase(std::remove_if(in.begin(), in.end(), ispunct), in.end());
//Создаем массив со словами
{
std::istringstream ss(in);
while(ss >> in)
words.push_back(in);
}
//Удаляем не подходящие слова
words.erase(std::remove_if(words.begin(), words.end(), [lastword = words.back()](const std::string& s){
return !(s.size() > 0 && *s.begin() == 'a' && s != lastword);
}), words.end());
//Выводим их на экран
for(const std::string& word : words){
std::cout << word << std::endl;
}
return 0;
}
Www.rostisl@w.md .
Спасибо, не знаю верный или неверный код для моей задачи... сейчас буду разбираться в коде...
#include <iostream>
#include <windows.h>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
setlocale(LC_ALL, "rus");
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
system("color 0A");
//cout << (char)toupper(static_cast<unsigned char>('п'));
cout << "Введите слова" << endl;
string s;
getline(cin, s);
stringstream ss(s);
vector<string> words;
for (; ss;)
{
string str;
ss >> str;
words.push_back(str);
}
words.pop_back();
words[words.size() - 1].pop_back();
cout << "Слова, удовлетворяющие условию" << endl;
for (const auto &word : words)
{
if (words[words.size() - 1] != word)
{
bool flag = true;
auto old = 'A' - 1;
for (const auto &c : word)
{
auto cup = toupper(static_cast<unsigned char>(c));
if (cup < 'A' || cup > 'Z' || cup != old + 1)
{
flag = false;
break;
}
old = cup;
}
if (flag)
{
cout << word << endl;
}
}
}
cout << endl;
system("pause");
return 0;
}

#include <windows.h>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
setlocale(LC_ALL, "rus");
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
system("color 0A");
//cout << (char)toupper(static_cast<unsigned char>('п'));
cout << "Введите слова" << endl;
string s;
getline(cin, s);
stringstream ss(s);
vector<string> words;
for (; ss;)
{
string str;
ss >> str;
words.push_back(str);
}
words.pop_back();
words[words.size() - 1].pop_back();
cout << "Слова, удовлетворяющие условию" << endl;
for (const auto &word : words)
{
if (words[words.size() - 1] != word)
{
bool flag = true;
auto old = 'A' - 1;
for (const auto &c : word)
{
auto cup = toupper(static_cast<unsigned char>(c));
if (cup < 'A' || cup > 'Z' || cup != old + 1)
{
flag = false;
break;
}
old = cup;
}
if (flag)
{
cout << word << endl;
}
}
}
cout << endl;
system("pause");
return 0;
}

Www.rostisl@w.md .
Спасибо, буду разбираться в коде...
Похожие вопросы
- Помогите решить задачи на C#
- Помогите решить задачу (Visual c++)
- Помогите решить задачу в visual studio c++
- Помогите решить задачи по C++
- Помогите решить задачу по C++
- помогите решить задачу пожалуйста на языке C++
- помогите решить задачу математически. C++
- Помогите решить задачу на C++
- Помогите решить задачу на C++. Двумерные массивы.
- помогите решить задачу на c++