#include <algorithm>
#include <string>
#include <vector>
#include <cctype>
#include <iostream>

typedef std::vector<std::string> StringVect;
std::string sequence = "QWERTYUIOPASDFGHJKLZXCVBNM";
std::vector<int> lookup(26);

bool getless(const std::string& s1, const std::string& s2)
{
    for (size_t i = 0; i < std::min(s1.size(), s2.size()); ++i)
        if (s1[i] != s2[i])
            return (lookup[toupper(s1[i])-'A'] < lookup[toupper(s2[i])-'A']);
    return s1.size() < s2.size();
};

int main()
{
    StringVect sv = {{ "apple" },{ "pear" },{ "peach" }};

    // build the lookup table
    int i = 0;
    std::for_each(sequence.begin(), sequence.end(), [&](char ch) {lookup[ch-'A'] = i; ++i; });

    // sort the data
    std::sort(sv.begin(), sv.end(), getless);

    // output results
    for (auto& s : sv)
      std::cout << s << "\n";
}