Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <compare>
- #include <absl/time/time.h>
- #include <absl/time/clock.h>
- #include <sstream>
- #include <map>
- #include <regex>
- #include <absl/algorithm/container.h>
- #include <absl/strings/str_split.h>
- using namespace std;
- using namespace absl;
- int main() {
- std::vector<std::string> patterns;
- int ans = 0;
- for (std::string line; std::getline(std::cin, line);) {
- vector<string> s = StrSplit(line, "|");
- stringstream patterns(s[0]);
- vector<string> p;
- string x;
- while (patterns >> x) {
- p.push_back(x);
- }
- stringstream out1(s[1]);
- while (out1 >> x) {
- p.push_back(x);
- }
- vector<set<char>> A(10);
- for (auto s: p) {
- if (s.length() == 2) {
- for (auto c: s) A[1].insert(c);
- }
- if (s.length() == 3) {
- for (auto c: s) A[7].insert(c);
- }
- if (s.length() == 4) {
- for (auto c: s) A[4].insert(c);
- }
- if (s.length() == 7) {
- for (auto c: s) A[8].insert(c);
- }
- }
- for (auto s: p) {
- set<char> ss;
- for (auto c: s) {
- ss.insert(c);
- }
- if (s.length() == 6) {
- bool is_six = false;
- for (auto c: A[1]) {
- if (!ss.contains(c)) {
- for (auto c: s) A[6].insert(c);
- is_six = true;
- }
- }
- bool is_zero = false;
- if (!is_six) {
- for (auto c: A[4]) {
- if (!ss.contains(c)) {
- for (auto c: s) A[0].insert(c);
- is_zero = true;
- }
- }
- }
- if (!is_zero && !is_six) {
- for (auto c: s) A[9].insert(c);
- }
- }
- if (s.length() == 5) {
- bool one = true;
- bool seven = true;
- int four = 0;
- for (auto c: A[1]) {
- if (!ss.contains(c)) {
- one = false;
- }
- }
- for (auto c: A[4]) {
- if (ss.contains(c)){
- ++four;
- }
- }
- for (auto c: A[7]) {
- if (!ss.contains(c)){
- seven = false;
- }
- }
- if (!one && !seven && four == 2) {
- for (auto c: s) A[2].insert(c);
- }
- if (one && seven && four == 3) {
- for (auto c: s) A[3].insert(c);
- }
- if (!one && !seven && four == 3) {
- for (auto c: s) A[5].insert(c);
- }
- }
- }
- // 0: 6 (+1, +7, -4)
- // 1: 2
- // 2: 5 (-1, -7, -4)
- // 3: 5 (+1, +7, -4)
- // 4: 4
- // 5: 5 (-1, -7, -4)
- // 6: 6 (-1, -7, -4)
- // 7: 3
- // 8: 7
- // 9: 6 (+1, +7, +4)
- stringstream outs(s[1]);
- int pow = 1000;
- int num = 0;
- while (outs >> x) {
- int n = -1;
- for (int i = 0; i < A.size(); ++i) {
- if (A[i].size() != x.length()) continue;
- bool all = true;
- for (auto c: x) {
- if (!A[i].contains(c)) {
- all = false;
- break;
- }
- }
- if (all) {
- n = i;
- break;
- }
- }
- num += pow * n;
- pow /= 10;
- }
- ans += num;
- cout << num << endl;
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment