Notice: file_put_contents(): Write of 4227 bytes failed with errno=28 No space left on device in /var/www/tgoop/post.php on line 50

Warning: file_put_contents(): Only 12288 of 16515 bytes written, possibly out of free disk space in /var/www/tgoop/post.php on line 50
C++ Academy@cpluspluc P.1136
CPLUSPLUC Telegram 1136
🔥 Совет дня: быстро посчитать частоты элементов в C++ с `std::unordered_map`

Когда нужно подсчитать, сколько раз каждый элемент встречается в векторе — не пиши вручную поиск. Просто используй unordered_map:


#include <iostream>
#include <vector>
#include <unordered_map>

int main() {
std::vector<std::string> items = {"apple", "banana", "apple", "orange", "banana", "apple"};
std::unordered_map<std::string, int> freq;

for (const auto& item : items) {
++freq[item];
}

for (const auto& [key, count] : freq) {
std::cout << key << ": " << count << "\n";
}
// 👉 apple: 3, banana: 2, orange: 1
}


📌 Удобно для:
— анализа строк
— парсинга логов
— простых хэш-агрегаций


@cpluspluc
18😴4🙈1🗿1



tgoop.com/cpluspluc/1136
Create:
Last Update:

🔥 Совет дня: быстро посчитать частоты элементов в C++ с `std::unordered_map`

Когда нужно подсчитать, сколько раз каждый элемент встречается в векторе — не пиши вручную поиск. Просто используй unordered_map:


#include <iostream>
#include <vector>
#include <unordered_map>

int main() {
std::vector<std::string> items = {"apple", "banana", "apple", "orange", "banana", "apple"};
std::unordered_map<std::string, int> freq;

for (const auto& item : items) {
++freq[item];
}

for (const auto& [key, count] : freq) {
std::cout << key << ": " << count << "\n";
}
// 👉 apple: 3, banana: 2, orange: 1
}


📌 Удобно для:
— анализа строк
— парсинга логов
— простых хэш-агрегаций


@cpluspluc

BY C++ Academy


Share with your friend now:
tgoop.com/cpluspluc/1136

View MORE
Open in Telegram


Telegram News

Date: |

Judge Hui described Ng as inciting others to “commit a massacre” with three posts teaching people to make “toxic chlorine gas bombs,” target police stations, police quarters and the city’s metro stations. This offence was “rather serious,” the court said. On Tuesday, some local media outlets included Sing Tao Daily cited sources as saying the Hong Kong government was considering restricting access to Telegram. Privacy Commissioner for Personal Data Ada Chung told to the Legislative Council on Monday that government officials, police and lawmakers remain the targets of “doxxing” despite a privacy law amendment last year that criminalised the malicious disclosure of personal information. bank east asia october 20 kowloon Avoid compound hashtags that consist of several words. If you have a hashtag like #marketingnewsinusa, split it into smaller hashtags: “#marketing, #news, #usa. Image: Telegram.
from us


Telegram C++ Academy
FROM American