fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. int main() {
  7. std::string input;
  8. std::cin >> input;
  9.  
  10. std::vector<std::string> passwords;
  11. std::string password = "";
  12.  
  13. for (int i = 0; i < input.size(); ++i) {
  14. int digit = input[i] - '0';
  15.  
  16. // If the current digit is between 1 and 9, append the corresponding character to the password
  17. if (digit >= 1 && digit <= 9) {
  18. char ch = 'a' + digit - 1;
  19. password += ch;
  20. passwords.push_back(password);
  21. password.pop_back(); // Remove the last character to backtrack
  22. }
  23.  
  24. // If there are two digits left and they represent a number between 10 and 26, append the corresponding character
  25. if (i + 1 < input.size()) {
  26. int twoDigit = (input[i] - '0') * 10 + (input[i + 1] - '0');
  27. if (twoDigit >= 10 && twoDigit <= 26) {
  28. char ch = 'a' + twoDigit - 1;
  29. password += ch;
  30. passwords.push_back(password);
  31. password.pop_back(); // Remove the last character to backtrack
  32. }
  33. }
  34. }
  35.  
  36. // Sort the generated passwords in lexicographic order
  37. std::sort(passwords.begin(), passwords.end());
  38.  
  39. // Print the sorted passwords
  40. for (const std::string& password : passwords) {
  41. std::cout << password << std::endl;
  42. }
  43.  
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0.01s 5424KB
stdin
1234
stdout
a
b
c
d
l
w