Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define all(x) x.begin(), x.end()
- #define fast_pls ios_base::sync_with_stdio(false); cin.tie(NULL);
- using namespace std;
- using ll = unsigned long long;
- const ll INF = 1e9 + 100;
- const int N = 1e5;
- int main() {
- /// freopen("in.txt", "r", stdin);
- int n;
- scanf("%d", &n);
- vector<vector<int>> a(n);
- vector<string> ans(n);
- for (int i = 0; i < n; i++) {
- string s;
- scanf(" ");
- getline(cin, s);
- for (int j = 0; j < s.size(); j++) {
- if (isdigit(s[j]))
- a[i].push_back(s[j] - '0');
- }
- }
- int m;
- scanf("%d", &m);
- for (int i = 0; i < m; i++) {
- string CC, OC, PC, C;
- cin >> CC >> OC >> PC;
- CC.erase(CC.begin());
- OC.erase(OC.begin());
- OC.pop_back();
- string shablon = CC + OC + PC;
- cin >> C;
- scanf(" ");
- getline(cin, C);
- for (int j = 0; j < n; j++) {
- if (shablon.size() != a[j].size()) continue;
- bool f = true;
- for (int l = 0; l < shablon.size(); l++) {
- if (isdigit(shablon[l])) {
- if (shablon[l] - '0' != a[j][l])
- f = false;
- }
- }
- if (f) {
- string res;
- res.push_back('+');
- for (int l = 0; l < CC.size(); l++) res.push_back(a[j][l] + '0');
- res.append(" (");
- for (int l = 0; l < OC.size(); l++) res.push_back(a[j][l + CC.size()] + '0');
- res.append(") ");
- for (int l = 0; l < PC.size(); l++) res.push_back('0' + a[j][l + CC.size() + OC.size()]);
- res.append(" - ");
- res.append(C);
- ans[j] = std::move(res);
- }
- }
- }
- for (int i = 0; i < n; i++) cout << ans[i] << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement