Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <queue>
- #include <string>
- #include <unordered_map>
- #include <unordered_set>
- int main1() {
- int n = 0; std::cin >> n;
- std::unordered_set<std::string> accounts;
- std::unordered_set<std::string> spamers;
- for (int i = 0; i < n; ++i) {
- std::string key; std::cin >> key;
- if (!accounts.contains(key)) {
- accounts.insert(key);
- } else {
- spamers.insert(key);
- }
- }
- for (const auto& spamer : spamers) {
- std::cout << spamer << "\n";
- }
- return 0;
- }
- int main2() {
- int n = 0; std::cin >> n;
- // 0 – аккаунт не спамер, 1 – спамер
- std::unordered_map<std::string, bool> accounts;
- for (int i = 0; i < n; ++i) {
- std::string key; std::cin >> key;
- if (!accounts.contains(key)) {
- accounts[key] = false;
- } else {
- accounts[key] = true;
- }
- }
- // for (std::unordered_map<std::string, bool>::iterator it = accounts.begin(); it != accounts.end(); ++it) {
- // if (it->second) std::cout << it->first << "\n";
- // }
- for (auto& [account, is_spamer] : accounts) {
- if (is_spamer) std::cout << account << "\n";
- }
- return 0;
- }
- int main3() {
- int n = 0; std::cin >> n;
- // Значение – число посылок
- std::unordered_map<std::string, int> accounts;
- for (int i = 0; i < n; ++i) {
- std::string key; std::cin >> key;
- // if (!accounts.contains(key)) accounts[key] = 1;
- // else ++accounts[key];
- ++accounts[key];
- }
- for (auto& [account, submits] : accounts) {
- if (submits >= 3) std::cout << account << "\n";
- }
- return 0;
- }
- int main4() {
- int n = 0; std::cin >> n;
- std::unordered_map<std::string, std::unordered_set<std::string>> connections;
- for (int i = 0; i < n; ++i) {
- std::string key1, key2, key3; std::cin >> key1 >> key2 >> key3;
- connections[key1].insert(key2);
- connections[key2].insert(key1);
- connections[key1].insert(key3);
- connections[key3].insert(key1);
- connections[key2].insert(key3);
- connections[key3].insert(key2);
- }
- // Значение – число Исенбаева
- std::map<std::string, int> accounts;
- for (auto& [key, _] : connections) accounts[key] = -1;
- accounts["Isenbaev"] = 0;
- // Обход BFS
- std::queue<std::string> q;
- q.push("Isenbaev");
- while (!q.empty()) {
- std::string current = q.front(); q.pop();
- for (auto& frnd : connections[current]) {
- if (accounts[frnd] == -1) {
- q.push(frnd);
- accounts[frnd] = accounts[current] + 1;
- }
- }
- }
- for (auto& [account, Isenbaev_count] : accounts) {
- std::cout << account << " " << (Isenbaev_count == -1 ? "undefined" : std::to_string(Isenbaev_count)) << "\n";
- }
- return 0;
- }
- struct Account {
- std::string Name;
- int Score = 0;
- bool operator==(const Account& other) const { return Name == other.Name && Score == other.Score; }
- };
- namespace std {
- template <>
- struct hash<Account> {
- size_t operator()(const Account& a) const {
- return std::hash<std::string>()(a.Name) * 37 + a.Score;
- }
- };
- }
- struct MyHash2 {
- size_t operator()(const Account& a) const {
- return std::hash<std::string>()(a.Name) * 37 + a.Score;
- }
- };
- int main() {
- std::string s = "Isenbaev";
- std::cout << std::hash<std::string>()(s) << std::endl;
- std::unordered_set<Account, MyHash2> ht;
- ht.insert({"Oparin", 1});
- for (auto& key : ht) std::cout << key.Name << " ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement