35657

Untitled

Oct 12th, 2024
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. void get_combo(int n, const std::string& str, std::string prefix, std::string* arr) {
  5.     if (n == str.size()) {
  6.         std::cout << prefix << " ";
  7.         return;
  8.     }
  9.     for (int i = 0; i < arr[str[n] - '2'].size(); i++) {
  10.         get_combo(n + 1, str, prefix + arr[str[n] - '2'][i], arr);
  11.     }
  12. }
  13.  
  14. int main() {
  15.    
  16.     std::string arr[8]{ "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
  17.  
  18.     std::string str;
  19.  
  20.     std::cin >> str;
  21.  
  22.     get_combo(0, str, "", arr);
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment