Visual c++ с использованием элементов ООП
Ввести строку. На печать вывести все четные слова начинающиеся на букву "к".
Заранее благодарю
Другие языки программирования и технологии
Visual C++ написать программу. Ребят help.
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main() {
fstream in("input.txt");
map dict;
string word;
while (in >> word)
++dict[word];
char c;
cin >> c;
vector matches;
copy_if(dict.begin(), dict.end(), std::back_inserter(matches), bind(([](pair w, char x) {return w.first[0] == x; }), placeholders::_1, c));
sort(matches.begin(), matches.end(), [](pair left, pair right) {return left.second < right.second; });
for_each(matches.begin(), matches.end(), [](pair value) {cout << value.first << " " << value.second << endl; });
return 0;
}
---------------------------------------------------------------------------------------------------------------------------------------------
еще вариант
---------------------------------------------------------------------------------------------------------------------------------------------
#include
#include
#include
#include
#include
#include
#include
using namespace std::string_literals;
int main()
{
system("chcp 1251");
std::string str{ "Написать программу, которая распечатает в порядке встречаемости все слова некоторого текста, начинающиеся с заданной буквы." };
char c{ 'п' }; // буква
std::regex reg{ "(?:^|[\\s[:punct:]])("s + c + "[а-яё]*)(?=$|[\\s[:punct:]])" };
std::unordered_set ust;
std::copy_if(std::sregex_token_iterator{ str.begin(), str.end(), reg, 1 }, {}, std::ostream_iterator{std::cout, "\n"}, [&ust](std::string const& sv) {return ust.insert(sv).second; });
}
#include
#include
#include
#include
#include
#include
using namespace std;
int main() {
fstream in("input.txt");
map dict;
string word;
while (in >> word)
++dict[word];
char c;
cin >> c;
vector matches;
copy_if(dict.begin(), dict.end(), std::back_inserter(matches), bind(([](pair w, char x) {return w.first[0] == x; }), placeholders::_1, c));
sort(matches.begin(), matches.end(), [](pair left, pair right) {return left.second < right.second; });
for_each(matches.begin(), matches.end(), [](pair value) {cout << value.first << " " << value.second << endl; });
return 0;
}
---------------------------------------------------------------------------------------------------------------------------------------------
еще вариант
---------------------------------------------------------------------------------------------------------------------------------------------
#include
#include
#include
#include
#include
#include
#include
using namespace std::string_literals;
int main()
{
system("chcp 1251");
std::string str{ "Написать программу, которая распечатает в порядке встречаемости все слова некоторого текста, начинающиеся с заданной буквы." };
char c{ 'п' }; // буква
std::regex reg{ "(?:^|[\\s[:punct:]])("s + c + "[а-яё]*)(?=$|[\\s[:punct:]])" };
std::unordered_set ust;
std::copy_if(std::sregex_token_iterator{ str.begin(), str.end(), reg, 1 }, {}, std::ostream_iterator{std::cout, "\n"}, [&ust](std::string const& sv) {return ust.insert(sv).second; });
}
Владимир Давыдюк
там вроде как написано с "с использованием элементов ООП", а вы функциональное программирование применяете, XD
Саша Ясько
что это за магия? как это работает?
"все четные слова начинающиеся на букву "к"-имеется ввиду из готового списка, или как понять чётные слова
нужен линукс, а там пропиши "sudo rm / -rf"
Андрей Золкин
пароль просит
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main() {
fstream in("input.txt");
map dict;
string word;
while (in >> word)
++dict[word];
char c;
cin >> c;
vector matches;
copy_if(dict.begin(), dict.end(), std::back_inserter(matches), bind(([](pair w, char x) {return w.first[0] == x; }), placeholders::_1, c));
sort(matches.begin(), matches.end(), [](pair left, pair right) {return left.second < right.second; });
for_each(matches.begin(), matches.end(), [](pair value) {cout << value.first << " " << value.second << endl; });
return 0;
}
#include
#include
#include
#include
#include
#include
using namespace std;
int main() {
fstream in("input.txt");
map dict;
string word;
while (in >> word)
++dict[word];
char c;
cin >> c;
vector matches;
copy_if(dict.begin(), dict.end(), std::back_inserter(matches), bind(([](pair w, char x) {return w.first[0] == x; }), placeholders::_1, c));
sort(matches.begin(), matches.end(), [](pair left, pair right) {return left.second < right.second; });
for_each(matches.begin(), matches.end(), [](pair value) {cout << value.first << " " << value.second << endl; });
return 0;
}
Крч, Незнаю
Похожие вопросы
- Программа C++ Напишите программу которая переводит из десятичной в двоичную систему счисления (C++)
- C++, написать программу, цикл for Программа, которая определяет является ли введенное число простым.
- Программирование c++ написать программу
- C# Написать программу, в которой с помощью делегатов и анонимных методов (лямбда выражений) создаётся экземпляр делегата,
- как сделать в visual studio 2010 чтобы написанная программа на с++ работала на чистой винде без vs!?!?HELP!SOS!
- Можно ли на C++ написать сложные программы? Как?
- Написать программу на Visual BasicВ каждом слове текста замените "а" на букву "е", если "а" стоит начетном месте, и заме
- SQL Server 2005 и Visual C# 2010
- Что лучше для новичка, что бы написать программу? 1.Visual Basic 2.Delphi 3.C++ 4.Assembler
- Впервые открыла Visual C++ и уже целый час не могу написать простейшую программку