Advertisement
bogolyubskiyalexey

Untitled

Feb 2nd, 2021
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. //Q
  2.  
  3. // - add str
  4. // - pop str
  5.  
  6.  
  7. #include <iostream>
  8. #include <string>
  9. #include <unordered_set>
  10.  
  11. /*
  12. add abcd  // (4)
  13. add def   // (4, 3)
  14. pop qwe   //
  15. pop def
  16. pop abcd
  17.  
  18. */
  19.  
  20.  
  21.  
  22. int main() {
  23.     std::unordered_set<std::string_view> words; // error, correct: std::string_view -> std::string
  24.     std::string request;
  25.     std::string word;
  26.     while (std::cin >> request >> word) {
  27.         if (request == "add") {
  28.             words.insert(word);
  29.         } else if (request == "pop") {
  30.             std::unordered_set<std::string_view>::iterator it = words.find(word);
  31.             if (it == words.end()) {
  32.                 std::cout << "NO\n";
  33.             } else {
  34.                 std::cout << "YES\n";
  35.                 words.erase(it);
  36.             }
  37.         }
  38.     }
  39. }
  40.  
  41. std::set<int>::iterator it;
  42.  ++it;
  43.  --it;
  44.  
  45. std::advance(it, 10);
  46. std::advance(it, -10);
  47. std::distance(it, myset.end());
  48.  
  49. std::vector<int>::itearator it2;
  50. it2 += 3;
  51. it2 -= 4;
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement