ErnestGalbrun

Untitled

Dec 8th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. #include <compare>
  5. #include <absl/time/time.h>
  6. #include <absl/time/clock.h>
  7. #include <sstream>
  8. #include <map>
  9. #include <regex>
  10. #include <absl/algorithm/container.h>
  11. #include <absl/strings/str_split.h>
  12.  
  13. using namespace std;
  14. using namespace absl;
  15.  
  16. int main() {
  17.  
  18.     std::vector<std::string> patterns;
  19.     int ans = 0;
  20.     for (std::string line; std::getline(std::cin, line);) {
  21.         vector<string> s = StrSplit(line, "|");
  22.  
  23.         stringstream patterns(s[0]);
  24.         vector<string> p;
  25.         string x;
  26.         while (patterns >> x) {
  27.             p.push_back(x);
  28.         }
  29.  
  30.         stringstream out1(s[1]);
  31.         while (out1 >> x) {
  32.             p.push_back(x);
  33.         }
  34.         vector<set<char>> A(10);
  35.         for (auto s: p) {
  36.             if (s.length() == 2) {
  37.                 for (auto c: s) A[1].insert(c);
  38.             }
  39.             if (s.length() == 3) {
  40.                 for (auto c: s) A[7].insert(c);
  41.             }
  42.             if (s.length() == 4) {
  43.                 for (auto c: s) A[4].insert(c);
  44.             }
  45.             if (s.length() == 7) {
  46.                 for (auto c: s) A[8].insert(c);
  47.             }
  48.         }
  49.  
  50.  
  51.         for (auto s: p) {
  52.             set<char> ss;
  53.             for (auto c: s) {
  54.                 ss.insert(c);
  55.             }
  56.             if (s.length() == 6) {
  57.                 bool is_six = false;
  58.                 for (auto c: A[1]) {
  59.                     if (!ss.contains(c)) {
  60.                         for (auto c: s) A[6].insert(c);
  61.                         is_six = true;
  62.                     }
  63.                 }
  64.                 bool is_zero = false;
  65.                 if (!is_six) {
  66.                     for (auto c: A[4]) {
  67.                         if (!ss.contains(c)) {
  68.                             for (auto c: s) A[0].insert(c);
  69.                             is_zero = true;
  70.                         }
  71.                     }
  72.                 }
  73.                 if (!is_zero && !is_six) {
  74.                     for (auto c: s) A[9].insert(c);
  75.                 }
  76.             }
  77.  
  78.             if (s.length() == 5) {
  79.                 bool one = true;
  80.                 bool seven = true;
  81.                 int four = 0;
  82.                 for (auto c: A[1]) {
  83.                     if (!ss.contains(c)) {
  84.                         one = false;
  85.                     }
  86.                 }
  87.                 for (auto c: A[4]) {
  88.                     if (ss.contains(c)){
  89.                         ++four;
  90.                     }
  91.                 }
  92.                 for (auto c: A[7]) {
  93.                     if (!ss.contains(c)){
  94.                         seven = false;
  95.                     }
  96.                 }
  97.                 if (!one && !seven && four == 2) {
  98.                     for (auto c: s) A[2].insert(c);
  99.                 }
  100.                 if (one && seven && four == 3) {
  101.                     for (auto c: s) A[3].insert(c);
  102.                 }
  103.                 if (!one && !seven && four == 3) {
  104.                     for (auto c: s) A[5].insert(c);
  105.                 }
  106.             }
  107.         }
  108.  
  109.         // 0: 6 (+1, +7, -4)
  110.         // 1: 2
  111.         // 2: 5 (-1, -7, -4)
  112.         // 3: 5 (+1, +7, -4)
  113.         // 4: 4
  114.         // 5: 5 (-1, -7, -4)
  115.         // 6: 6 (-1, -7, -4)
  116.         // 7: 3
  117.         // 8: 7
  118.         // 9: 6 (+1, +7, +4)
  119.         stringstream outs(s[1]);
  120.         int pow = 1000;
  121.         int num = 0;
  122.         while (outs >> x) {
  123.             int n = -1;
  124.             for (int i = 0; i < A.size(); ++i) {
  125.                 if (A[i].size() != x.length()) continue;
  126.                 bool all = true;
  127.                 for (auto c: x) {
  128.                     if (!A[i].contains(c)) {
  129.                         all = false;
  130.                         break;
  131.                     }
  132.                 }
  133.                 if (all) {
  134.                     n = i;
  135.                     break;
  136.                 }
  137.             }
  138.             num += pow * n;
  139.             pow /= 10;
  140.         }
  141.         ans += num;
  142.         cout << num << endl;
  143.     }
  144.  
  145.     cout << ans << endl;
  146.     return 0;
  147. }
  148.  
Advertisement
Add Comment
Please, Sign In to add comment