// Arup Guha
// 8/26/2025
// Code for CIS 3362 Quiz #1 (Fall 25)

#include <stdio.h>
#include <stdlib.h>

// Returns the inverse mapping stored in code.
char* getInverse(char* code);

int main() {

    // Test it!
    char mine[27] = "QWERTYUIOPLKJHGFDSAZXCVBNM";
    char* rev = getInverse(mine);
    printf("%s\n", rev);
    free(rev);
    return 0;
}

// Given a substitution mapping stored in code (code[i] = c means that
// letter i should get substituted by character c. code must be a string
// of 26 distinct uppercase letters.
char* getInverse(char* code) {

    // Allocate space and put in the null character at the end.
    char* inverse = calloc(27, sizeof(char));
    inverse[26] = '\0';

    // Go through each letter in code.
    for (int i=0; i<26; i++)

        // If letter i goes to character code[i], then
        // index code[i]-'A' goes to the letter i,
        // which is i + 'A'.
        inverse[code[i]-'A'] = (char)('A'+i);

    // Return the pointer to the array.
    return inverse;
}
