#include <iostream>
#include <map>
int main()
{
using namespace std::string_literals;
auto m = std::map<int,std::string>{
{1,"гриб"s},
{2,"гриба"s},
{3,"грибов"s},
};
auto txt = "гриб"s;
auto k = int{};
std::cin >> k;
auto k10 = k % 10;
auto k100 = k % 100;
if (k100 == 0) txt = m.at(3);
else if (k100 == 1) txt = m.at(1);
else if (k100 < 5) txt = m.at(2);
else txt = m.at(3);
if (k100 > 20)
{
if (k10 == 0) txt = m.at(3);
else if (k10 == 1) txt = m.at(1);
else if (k10 < 5) txt = m.at(2);
else txt = m.at(3);
}
std::cout << "Мы нашли " << k << " " << txt << '\n';
}
#include <random>
#include <iostream>
int GetRandomNumber(int min, int max)
{
auto rnd = std::random_device{};
auto gen = std::mt19937_64{rnd()};
auto dis = std::uniform_int_distribution<int>{min, max};
return dis(gen);
}
int main()
{
auto number = GetRandomNumber(0, 20);
std::cout << "number = " << number << '\n';
}
#include <iostream>
#include <vector>
class Data
{
private:
std::vector<int> elements;
std::size_t N;
public:
explicit Data(const std::size_t size)
: N{size}
{
elements.reserve(size);
elements.resize(size);
}
void fill()
{
std::cout << "Enter elements of array:" << std::endl;
auto index = std::size_t{};
for (auto &elem : elements)
std::cin >> elements.at(index++);
}
void process(const int x)
{
if (x == elements.at(0))
{
elements.at(0) = elements.at(N - 1);
elements.at(N - 1) = x;
std::cout << "Array after swapping first and last elements: ";
for (const auto &elem : elements)
std::cout << elem << " ";
}
else
std::cout << "Error";
}
};
int main()
{
auto x = int{};
auto n = std::size_t{};
std::cout << "Enter x: ";
std::cin >> x;
std::cout << "Enter Number of array elements: ";
std::cin >> n;
auto data = Data{n};
data.fill();
data.process(x);
return 0;
}
#include <random>
#include <iostream>
int main()
{
auto n = 9;
auto rnd = std::random_device{};
auto gen = std::mt19937_64{rnd()};
auto dis = std::uniform_real_distribution<double>{-0.1, 0.2};
auto res = std::vector<double>{};
std::generate_n(
std::inserter(res, std::end(res)),
n,
[&](){ return dis(gen); });
for (const auto& elem: res)
{
std::cout << elem << '\n';
}
}