Mikki0

Untitled

Sep 20th, 2021
670
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <fstream>
  3. #include <iostream>
  4. #include <iterator>
  5. #include <unordered_map>
  6. #include <vector>
  7.  
  8. int main() {
  9.     std::ifstream input( "Image.png", std::ios::binary);
  10.     freopen("output.txt", "w", stdout);
  11.     std::vector<unsigned char> buffer(std::istreambuf_iterator<char>(input), {});
  12.     std::unordered_map<std::string, size_t> dict;
  13.     for (size_t i = 0; i < 256; ++i) {
  14.         dict[std::string(1, static_cast<unsigned char>(i))] = i;
  15.     }
  16.     std::string cur;
  17.     std::vector<size_t> answer;
  18.     for (auto el : buffer) {
  19.         if (!dict.contains(cur + el)) {
  20.             dict[cur + el] = dict.size();
  21.             answer.push_back(dict[cur]);
  22.             cur.clear();
  23.         }
  24.         cur += el;
  25.     }
  26.     answer.push_back(dict[cur]);
  27.     std::cout << answer.size() << '\n';
  28.     for (auto el : answer) {
  29.         std::cout << el << ' ';
  30.     }
  31. }
RAW Paste Data