#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
struct my_struct
{
std::string first_name;
std::string last_name;
};
int main()
{
std::vector<my_struct> my_vector(5);
my_vector[0].first_name = "David";
my_vector[0].last_name = "Andriw";
my_vector[1].first_name = "Jhon";
my_vector[1].last_name = "Monta";
my_vector[2].first_name = "Jams";
my_vector[2].last_name = "Ruth";
my_vector[3].first_name = "David";
my_vector[3].last_name = "AAA";
my_vector[4].first_name = "Jhon";
my_vector[4].last_name = "BBB";
for(int i = 0; i < my_vector.size(); i++)
{
int my_count = std::count_if(my_vector.begin(), my_vector.end(),
[&](const my_struct& s) {
return s.first_name == my_vector[i].first_name;
});
std::cout << "First_Name: " << my_vector[i].first_name << "\tCOUNT: " << my_count << std::endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RyaW5nPgoKc3RydWN0IG15X3N0cnVjdAp7CiAgICBzdGQ6OnN0cmluZyBmaXJzdF9uYW1lOwogICAgc3RkOjpzdHJpbmcgbGFzdF9uYW1lOwp9OwoKaW50IG1haW4oKQp7CiAgc3RkOjp2ZWN0b3I8bXlfc3RydWN0PiBteV92ZWN0b3IoNSk7CgogIG15X3ZlY3RvclswXS5maXJzdF9uYW1lID0gIkRhdmlkIjsKICBteV92ZWN0b3JbMF0ubGFzdF9uYW1lID0gIkFuZHJpdyI7CgogIG15X3ZlY3RvclsxXS5maXJzdF9uYW1lID0gIkpob24iOwogIG15X3ZlY3RvclsxXS5sYXN0X25hbWUgPSAiTW9udGEiOwoKICBteV92ZWN0b3JbMl0uZmlyc3RfbmFtZSA9ICJKYW1zIjsKICBteV92ZWN0b3JbMl0ubGFzdF9uYW1lID0gIlJ1dGgiOwoKICBteV92ZWN0b3JbM10uZmlyc3RfbmFtZSA9ICJEYXZpZCI7CiAgbXlfdmVjdG9yWzNdLmxhc3RfbmFtZSA9ICJBQUEiOwoK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