Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <unordered_map>
  3. #include <unordered_set>
  4. #include <sstream>
  5.  
  6. #pragma GCC optimize ("O3")
  7.  
  8. int main() {
  9.   std::ostream::sync_with_stdio(false);
  10.   std::istream::sync_with_stdio(false);
  11.   std::cin.tie(nullptr);
  12.  
  13.   std::unordered_set<int> separators;
  14.   std::unordered_map<int, int> numbersWithCount;
  15.  
  16.   std::string line;
  17.   int num;
  18.   getline(std::cin, line);
  19.  
  20.   std::istringstream iss(line);
  21.   while (iss >> num) {
  22.     separators.emplace(num);
  23.   }
  24.  
  25.   getline(std::cin, line);
  26.   iss.clear();
  27.   iss.str(line);
  28.   std::unordered_set<int> currentGroup;
  29.   while (iss >> num) {
  30.     if (separators.find(num) == separators.end()) {
  31.       currentGroup.emplace(num);
  32.     } else {
  33.       for (auto const& n: currentGroup) {
  34.         ++numbersWithCount[n];
  35.       }
  36.       currentGroup.clear();
  37.     }
  38.   }
  39.  
  40.   if (!currentGroup.empty()) {
  41.     for (auto const& n: currentGroup) {
  42.       ++numbersWithCount[n];
  43.     }
  44.   }
  45.  
  46.   std::ostringstream oss;
  47.   while (std::cin >> num && num != 0) {
  48.     oss << numbersWithCount[num] << std::endl;
  49.   }
  50.  
  51.   std::cout << oss.str();
  52.  
  53.   return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement