How to do this question using string concept? I did it using char array, but according to ques we are supposed to do this using string.
I’m not able to do that and getting errors while using strings.
Please help me out, thanks.
How to do this question using string concept? I did it using char array, but according to ques we are supposed to do this using string.
I’m not able to do that and getting errors while using strings.
Please help me out, thanks.
Hey @gambhirrahul0 in question where there is string mentioned it doesn’t mean to solve it using string data type. You can use it using character array too.
Yes, I know. But I want to do this using string to revise the concepts as I face difficulties in string.
Okay so if you use string data type, instead of char array just make sure to append when you have to add keypad[digit][k]
Just do it with output string
Output+= keypad[digit][k]
#include <iostream>
#include <cstring>
using namespace std;
string table[] = {" ", ".+@$", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
void phoneKeypad(string inp, string out)
{
//Base case
if (inp.size() == 0)
{
cout << out << "\n";
return;
}
//Rec case
int r = inp[0] - '0';
for (unsigned int k = 0; k < table[r].length(); k++)
{
char ch = table[r][k];
phoneKeypad(inp.substr(1), out + ch);
}
}
int main()
{
string input;
cin >> input;
phoneKeypad(input, "");
return 0
}
Okay, I’ll go through the code and will get back to you. Thanks
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.