Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unordered_set>
- struct Node {
- std::string product_name;
- int color;
- int size;
- bool operator==(const Node &other) const {
- return product_name == other.product_name && color == other.color && size == other.size;
- }
- };
- template <> struct std::hash<Node> {
- size_t operator()(const Node &key) const {
- size_t h1 = std::hash<std::string> {} (key.product_name);
- size_t h2 = std::hash<int> {} (key.color);
- size_t h3 = std::hash<int> {} (key.size);
- return h1 ^ (h2 << 1) ^ (h3 << 2);
- }
- };
- int main() {
- std::unordered_set<Node> set;
- char query;
- std::string name;
- int color;
- int size;
- while(std::cin >> query >> name >> color >> size) {
- Node _new;
- _new.product_name = name;
- _new.color = color;
- _new.size = size;
- switch(query) {
- case '+':
- if(set.insert(_new).second)
- std::cout << "OK\n";
- else
- std::cout << "FAIL\n";
- break;
- case '-':
- if(set.erase(_new))
- std::cout << "OK\n";
- else
- std::cout << "FAIL\n";
- break;
- case '?':
- if(set.count(_new))
- std::cout << "OK\n";
- else
- std::cout << "FAIL\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement