#include #include #include using namespace std; int main() { const string eng[] { "kyo","kya","kyu", "sha","shu","sho", "cha","chu","cho", "nya","nyu","nyo", "hya","hyu","hyo", "mya","myu","myo", "rya","ryu","ryo", "gya","gyu","gyo", "ja","ju","jo", "bya","byu","byo", "pya","pyu","pyo", "a","i","u","e","o", "ka","ki","ku","ke","ko", "sa","shi","su","se","so", "ta","chi","tsu","te","to", "na","ni","nu","ne","no", "ha","hi","fu","he","ho", "ma","mi","mu","me","mo", "ya","yu","yo", "ra","ri","ru","re","ro", "wa","wo","n" }; const string jap[] { "きょ","きゃ","きゅ", "しゃ","しゅ","しょ", "ちゃ","ちゅ","ちょ", "にゃ","にゅ","にょ", "ひゃ","ひゅ","ひょ", "みゃ","みゅ","みょ", "りゃ","りゅ","りょ", "ぎゃ","ぎゅ","ぎょ", "じゃ","じゅ","じょ", "びゃ","びゅ","びょ", "ぴゃ","ぴゅ","ぴょ", "あ","い","う","え","お", "か","き","く","け","こ", "さ","し","す","せ","そ", "た","ち","つ","て","と", "な","に","ぬ","ね","の", "は","ひ","ふ","へ","ほ", "ま","み","む","め","も", "や","ゆ","よ", "ら","り","る","れ","ろ", "わ","を","ん" }; const size_t n {size(eng)}; //number of elements in the array string romaji; cout << "Enter a romaji phrase (Japanese typed with ENG characters): "; cin >> romaji; //romaji represents the entire phrase the user types string output; size_t i {0}; while (i < romaji.size()) { bool match {false}; for (size_t j {0}; j < n; ++j) { //searching through the array element by element const string k {eng[j]}; //k represents a string that is a romaji syllable that comes from end[j]. I'm gonna use it to set the endpoint of the substring if (romaji.substr(i, k.size()) == k) { //cheeky substring modifier i had to look up how to use. divides romaji phrase into parts (i, k.size()) output += jap[j]; i += k.size(); match = true; break; } } if (!match) { output += ""; ++i; } } cout << output << " is the Japanese character for " << romaji << ".\n"; return EXIT_SUCCESS; }