#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define SET_LEN 50
#define INPUT_LEN 256

void clear_buffer();
void read_set(int set_number, char set[]);
void read_input_text(char text[]);
bool contains_same_letters(const char set[]);
int find_position(const char[], char);
void translate(const char set1[], const char set2[], const char text[], char translated[]);

int main() {
    // reading set 1
    char set1[SET_LEN];
    read_set(1, set1);

    // check for same letters
    if (contains_same_letters(set1)) {
        printf("Wrong input.\n");
        return -1;
    }

    // reading set 2
    char set2[SET_LEN];
    read_set(2, set2);

    // check for the same length
    if (strlen(set1) != strlen(set2)) {
        printf("Length of sets is different.\n");
        return -1;
    }

    // clear buffer
    clear_buffer();

    // reading text input
    char text[INPUT_LEN];
    read_input_text(text);

    // translation
    char translated[strlen(text) + 1];
    translate(set1, set2, text, translated);
    printf("%s", translated);

    return 0;
}

void clear_buffer() {
    while (getchar() != '\n');
}

void read_set(int set_number, char set[]) {
    printf("Enter set %d: ", set_number);
    scanf("%s", set);
}

void read_input_text(char text[]) {
    printf("Enter text to translate: ");
    fgets(text, INPUT_LEN, stdin);
}

bool contains_same_letters(const char set[]) {
    for (int index = 0, len = (int) strlen(set); index < len - 1; index++) {
        for (int index2 = index + 1; index2 < len; index2++) {
            if (set[index] == set[index2]) {
                return true;
            }
        }
    }
    return false;
}

int find_position(const char set1[], const char letter) {
    for (int index = 0, len = (int) strlen(set1); index < len; index++) {
        if (letter == set1[index]) {
            return index;
        }
    }
    return -1;
}

void translate(const char set1[], const char set2[], const char text[], char translated[]) {
    int len = (int) strlen(text);
    for (int index = 0; index < len; index++) {
        int position = find_position(set1, text[index]);
        translated[index] = position != -1 ? set2[position] : text[index];
    }
    translated[len] = '\0';
}
