class Solution {
public:
string decodeMessage(string key, string message) {
string letters = "abcdefghijklmnopqrstuvwxyz";
int index = 0;
for (int i = 0; i < key.length(); )
{
if (key[i] == ' ')
{
key.erase(i, 1);
continue;
}
else
{
for (int j = i + 1; j < key.length(); )
{
if (key[j] == key[i]) key.erase(j, 1);
else j++;
}
i++;
}
}
for (int i = 0; i < message.length(); i++)
{
if('a' <= message[i] && message[i] <= 'z')
{
index = key.find_first_of(message[i],0);
message[i] = letters[index];
}
}
return message;
}
};