Skip to content

Instantly share code, notes, and snippets.

@pradhuman-soni
Last active October 21, 2021 10:14
Show Gist options
  • Select an option

  • Save pradhuman-soni/bd30b59eabd1e32df2b923763cb1ce1b to your computer and use it in GitHub Desktop.

Select an option

Save pradhuman-soni/bd30b59eabd1e32df2b923763cb1ce1b to your computer and use it in GitHub Desktop.
pepcoding.com 21/10/2021 printKPC
#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
}
#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