Solution
Nothing much to it. Replace every character by the corresponding digit group.
Implementation
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    getline(cin, s);
    
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == ' ') {
            cout << "999";
        } else {
            char group = (s[i] - 97) / 3 + 1 + '0';
            int sub_group = (s[i] - 97) % 3 + 1;
            
            string res(sub_group, group);
            cout << res;
        }
    }
    
    cout << '\n';
}
- Time complexity: $\mathcal{O}(|s|)$
- Space complexity: $\mathcal{O}(|s|)$