Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <unordered_map>
- #include <map>
- #include <set>
- using namespace std;
- string shkilaGenerator(int n) {
- string tmp = "qwertyuiopasdfghjkl ";
- string result;
- for (int i = 0; i < n; i++) {
- int index = rand() % tmp.size();
- result += tmp[index];
- }
- return result;
- }
- template <typename T>
- void printM(const T& a) {
- cout << endl;
- for_each(a.cbegin(), a.cend(), [](auto p) { // []-захват области видимости,
- cout << setw(5) << p.first << " : " << p.second << endl;
- });
- cout << endl << endl;
- }
- template <typename T>
- void printV(const T& a) {
- cout << endl;
- for_each(a.cbegin(), a.cend(), [](auto p) {
- cout << p << endl;
- });
- cout << endl << endl;
- }
- int main() {
- unordered_multimap<int, string> shkila;
- srand(time(NULL));
- int k;
- cout << "Enter quantity of elements: "; cin >> k;
- for (int i = 0; i < k; i++) {
- shkila.insert({ (rand() % 20) - 10,shkilaGenerator(rand() % 15) });
- }
- printM(shkila);
- shkila.insert({ 4,shkilaGenerator(rand() % 15) });
- shkila.insert({ 4,shkilaGenerator(rand() % 15) });
- printM(shkila);
- // Находим ключ 2
- auto keyTwo = shkila.find(2);
- if (keyTwo != shkila.end()) {
- // Если нашли, то удаляем эту пару
- shkila.erase(shkila.find(2));
- }
- printM(shkila);
- map<int, string> mapShkila(shkila.begin(), shkila.end());
- printM(mapShkila);
- int countResult = count_if(mapShkila.begin(), mapShkila.end(), [](auto p) {
- return p.first > 0;
- });
- cout << endl << countResult << endl;
- vector<int> keys;
- transform(mapShkila.begin(), mapShkila.end(), back_inserter(keys), [](auto p) {
- return p.first;
- });
- printV(keys);
- auto keyOne = find(keys.begin(), keys.end(), 1);
- if (keyOne == keys.end()) {
- // Если не нашли
- cout << endl << "Not found" << endl;
- } else {
- cout << endl << "Index: " << keyOne - keys.begin() << endl;
- }
- replace_if(keys.begin(), keys.end(), [](auto value) {
- return value < 0;
- }, 0);
- printV(keys);
- sort(keys.begin(), keys.end(), [](auto value1, auto value2) {
- return value1 > value2;
- });
- printV(keys);
- set<int> setShkila(keys.begin(), keys.end());
- printV(setShkila);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement