#include #include #include #include using namespace std; vector KeyStrings, PossibleStrings; vector PressedKeys; void Back(const int index, string ¤tString) { if (index == int(PressedKeys.size())) { PossibleStrings.push_back(currentString); return; } for (int i = 0; i < int(KeyStrings[PressedKeys[index]].size()); ++i) { currentString.push_back(KeyStrings[PressedKeys[index]][i]); Back(index + 1, currentString); currentString.pop_back(); } } void Solve() { string currentString = ""; Back(0, currentString); sort(PossibleStrings.begin(), PossibleStrings.end()); PossibleStrings.erase(unique(PossibleStrings.begin(), PossibleStrings.end()), PossibleStrings.end()); } void Read() { KeyStrings = vector(10, ""); for (int i = 0; i < 10; ++i) cin >> KeyStrings[i]; string pressedKeys = ""; cin >> pressedKeys; PressedKeys = vector(int(pressedKeys.size())); for (int i = 0; i < int(pressedKeys.size()); ++i) PressedKeys[i] = int(pressedKeys[i] - '0'); } void Print() { for (int i = 0; i < int(PossibleStrings.size()); ++i) cout << PossibleStrings[i] << "\n"; } int main() { Read(); Solve(); Print(); return 0; }