Inverse of the permutation string

I need to get the inverse of the permutation string.

I was able to get the returned letter D from the string ***B* but I'm not sure how to put it back into the string using an array.

Declare an array of characters of size the length of the alphabet.
- Scan each character of the permutation string
- Find the position of the scanned character in the alphabet
- At this position in the array store the character whose position in the alphabet
is the position of the scanned character in the permutation string
- Declare an empty string
- Push back all array elements in this string
- Return this string


thank you in advance for any help.

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
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;

const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.,' ";

string inversePermutation(){

    string permuStr;
    char SizeALPHA[30];
    int position = 0;

    cout << "enter string" << endl; // example ***B*,
    getline(cin,permuStr);

    for(int i=0; i<permuStr.length();i++)
    {
        for(int j=0; j<ALPHABET.length();j++)
        {
            if(permuStr[i] == ALPHABET[j])
            {

                cout << permuStr << endl;
                cout << ALPHABET[i] << endl;

                /* supposed to return the letter e.g:   
                   01234 
                   ABCDE ALPHABET 
                   ***B* permutation
                   *D*** inverse permutation
                */
            }

        }
}
}
        
                                                
                                                
Topic archived. No new replies allowed.