#include <iostream>
#include <string>

std::string encrypt(const std::string& word)
{
    std::string result;

    if (word.size())    // sanity check for empty string
    {
        std::size_t i = 0;                  // index of leftmost character
        std::size_t j = word.size() - 1;    // index of rightmost character

        while (i < j)
        {
            result += word[i++];  // You get the first character of the word
            result += word[j--];  // and then you get the last character
        }

        if (i == j)   // in some cases of words with an odd number of characters, only one character is left!
            result += word[i];
    }

    return result;
}

int main()
{
    std::cout << encrypt("hacker") << '\n'; // even number of characters.
    std::cout << encrypt("phone") << '\n';  // odd number of characters.
}