forked from anuragb0012/HactoberFest21-DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard specified sequence : string
48 lines (40 loc) · 1.11 KB
/
keyboard specified sequence : string
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//program to convert string to keyboard specified sequence : love babbar sheet problems
#include<bits/stdc++.h>
using namespace std;
string KeypadSequenceConverter(string str[], string input)
{
int n=input.size();
string output="";
for (int i = 0; i < n;i++)
{
// CHARACTER IS SPACE THEN ADD 0 TO OUTPUT STRING
if(input[i]==' ')
{
output = output + "0";
}
// otherwise add specified string on the basis of array
else
{
output = output + str[input[i] - 'A'];
}
}
return output;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// storing the sequence in array
string str[] = {"2","22","222",
"3","33","333",
"4","44","444",
"5","55","555",
"6","66","666",
"7","77","777","7777",
"8","88","888",
"9","99","999","9999"
};
string input = "RISHABH BHATT";
cout << KeypadSequenceConverter(str, input);
return 0;
}