Click Here to go back to the homepage.

Nimionese Solution:


#include <bits/stdc++.h>
using namespace std;

std::vector<std::string> stringSplit(const std::string s, char delimiter){
   std::vector<std::string> tokens;
   std::string token;
   std::istringstream tokenStream(s);
   while (getline(tokenStream, token, delimiter)){
      tokens.push_back(token);
   }
   return tokens;
}

bool hardConsonants[128] = {};
const string lowerHardConsonants = "bcdgknpt";
const string upperHardConsonants = "BCDGLNPT";

void replaceFirst(string *word){
    char c = (*word)[0];
    int lowestDiff = 30;
    char toReplace;
    if(isupper(c)){
        for(int i = 0; i < 8; i++){
            int currDiff = abs(c - upperHardConsonants[i]);
            if(currDiff < lowestDiff){
                lowestDiff = currDiff;
                toReplace = upperHardConsonants[i];
            }
        }
    } else {
        for(int i = 0; i < 8; i++){
            int currDiff = abs(c - lowerHardConsonants[i]);
            if(currDiff < lowestDiff){
                lowestDiff = currDiff;
                toReplace = lowerHardConsonants[i];
            }
        }
    }
    (*word)[0] = toReplace;
    return;
}

void replaceRest(char c, string *word){
    for(char &ch: *word){
        if(hardConsonants[ch]){
            ch = c;
        }
    }
    return;
}

void replaceEnd(string *word){
    char c = (*word)[word->size() - 1];
    int lowestDiff = 30;
    char toReplace;
    char ending[3] = {'a', 'o', 'u'};
    for(int i = 0; i < 3; i++){
        int currDiff = abs(c - ending[i]);
        if(currDiff < lowestDiff){
            lowestDiff = currDiff;
            toReplace = ending[i];
        } 
    }
    word->push_back(toReplace);
    word->push_back('h');
    return;
}

string convert(string *word){
    vector<string> syllables = stringSplit(*word, '-');
    if(!hardConsonants[syllables[0][0]]){
        replaceFirst(&syllables[0]);
    }
    word->clear();
    word->append(syllables[0]);
    for(int i = 1; i < syllables.size(); i++){
        replaceRest(tolower(syllables[0][0]), &syllables[i]);
        word->append(syllables[i]);
    }
    if(hardConsonants[(*word)[word->size() - 1]]){
        replaceEnd(word);
    }
    return *word;
}


int main(){
    // #ifndef TESTING
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    for (char c: upperHardConsonants){
        hardConsonants[c] = true;
    }
    for (char c: lowerHardConsonants){
        hardConsonants[c] = true;
    }
    string word;
    while(cin >> word){
        cout << convert(&word) << " ";
    }

    return 0;   
}