geekbrains_cpp_difficult_mo.../lesson_5/exercise_1.hpp

39 lines
1.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* exercise_1.hpp
*
* Created on: 6 окт. 2021 г.
* Author: alexander
*/
#pragma once
#include <iostream>
#include <iterator>
#include <string>
#include <unordered_set>
#include <vector>
#include <list>
#include <deque>
template<typename IT>
void printWords(IT it, IT end)
{
std::unordered_set<std::string> countWords(it, end);
std::copy(countWords.begin(), countWords.end(), std::ostream_iterator<std::string>(std::cout, "; "));
}
void exercise_1()
{
std::vector<std::string> v { "Один", "Два", "Три", "Пять", "Один", "Пять", "Шесть", "Два", "Два", "Один", "Семь", "Девять" };
std::cout << "Вывод вектора:" << std::endl;
printWords(v.begin(), v.end());
std::list<std::string> l(v.begin(), v.end());
std::cout << "\nВывод листа:" << std::endl;
printWords(l.begin(), l.end());
std::deque<std::string> d(v.begin(), v.end());
std::cout << "\nВывод деки:" << std::endl;
printWords(d.begin(), d.end());
}