Advertisement
smatskevich

Lesson14

Dec 21st, 2023
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <unordered_map>
  3.  
  4. typedef long long ll;
  5.  
  6. using namespace std;
  7.  
  8. ll GetMask(ll a) {
  9.   ll mask = 0;
  10.   ll d = 1;
  11.   while (a) {
  12.     mask += (a & 1) * d;
  13.     a /= 10;
  14.     d *= 10;
  15.   }
  16.   return mask;
  17. }
  18.  
  19. int main() {
  20.   int n; cin >> n;
  21.   unordered_map<ll, int> m;
  22.   while (n--) {
  23.     char command;
  24.     ll value;
  25.     cin >> command >> value;
  26.     ll mask = GetMask(value);
  27.     if (command == '+') {
  28.       m[mask]++;
  29.     } else if (command == '-') {
  30.       m[mask]--;
  31.     } else if (command == '?') {
  32.       cout << m[mask] << "\n";
  33.     }
  34.   }
  35.   return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement