Skip to content

Instantly share code, notes, and snippets.

@XoLinA
Created December 24, 2025 11:27
Show Gist options
  • Select an option

  • Save XoLinA/2d6c3cc66c03d638a3b3e074f6b953c4 to your computer and use it in GitHub Desktop.

Select an option

Save XoLinA/2d6c3cc66c03d638a3b3e074f6b953c4 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
int main()
{
list<int> a = { 1, 2, 3, 4, 5 };
int k = count_if (a.begin(), a.end(),[](int x) { return x % 2 == 0; });
cout << "1) Even: " << k << endl;
vector<int> b = { 3, 6, 7, 8, 10 };
cout << "2) Even: ";
for_each(b.begin(), b.end(), [](int x){if (x % 2 == 0){cout << x << " ";}});
cout << endl;
vector<int> c = { -2, 5, -7, 9, -1 };
c.erase(remove_if(c.begin(), c.end(), [](int x) { return x < 0; }),c.end());
cout << "3) Del -n: ";
for (int i = 0; i < c.size(); i++)
{
cout << c[i] << " ";
}
cout << endl;
vector<string> s = { "meet", "sea", "son", "night" };
char ch = 's';
int cnt = count_if(s.begin(), s.end(), [ch](string x) { return x[0] == ch; });
cout << "4) Letter '" << ch << "': " << cnt << endl;
map<char, int> m;
for_each(s.begin(), s.end(),[&m](string x) {m[x[0]]++;});
cout << "5) By letter:" << endl;
for (auto it = m.begin(); it != m.end(); it++)
{
cout << it->first << " - " << it->second << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment