Last active
October 21, 2021 10:14
-
-
Save pradhuman-soni/bd30b59eabd1e32df2b923763cb1ce1b to your computer and use it in GitHub Desktop.
pepcoding.com 21/10/2021 printKPC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| string codes[] = {".;", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tu", "vwx", "yz"}; | |
| void printKPC(string ques, string asf){ | |
| if(ques.length() == 0) { //base case | |
| cout << asf << endl; | |
| return; | |
| } | |
| int idx = ques[0] - '0'; // converting the first character to number for index. | |
| for(int i = 0; i < codes[idx].length(); i++) { // loop for traversing the string at idx index of codes array | |
| string str = codes[idx]; // the string at idx location in codes array | |
| char ch = str[i]; // character to add to asf | |
| printKPC(ques.substr(1), asf + ch); // recursive call | |
| } | |
| } | |
| int main(){ | |
| string str; | |
| cin >> str; // input | |
| printKPC(str, ""); // function call | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| string codes[] = {".;", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tu", "vwx", "yz"}; | |
| void printKPC(string ques, string asf){ | |
| // write your code here | |
| } | |
| int main(){ | |
| string str; | |
| cin >> str; // input | |
| printKPC(str, ""); // function call | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment