Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- #include <string>
- #include <algorithm>
- using namespace std;
- #define ll long long
- int main()
- {
- string str;
- cout << "Enter the string: ";
- cin >> str;
- map< char, int > m;
- m['a'] = m['b'] = m['c'] = 2;
- m['d'] = m['e'] = m['f'] = 3;
- m['g'] = m['h'] = m['i'] = 4;
- m['j'] = m['k'] = m['l'] = 5;
- m['m'] = m['n'] = m['o'] = 6;
- m['p'] = m['q'] = m['r'] = m['s'] = 7;
- m['t'] = m['u'] = m['v'] = 8;
- m['w'] = m['x'] = m['y'] = m['z'] = 9;
- transform(str.begin(), str.end(), str.begin(), ::tolower);
- int n = str.size();
- cout << "Translated string: ";
- for(int i=0; i<n; i++) {
- if(str[i]>='0' && str[i]<='9') cout << str[i];
- else cout << m[str[i]];
- }
- cout << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement