#include #include #include #include using namespace std; static bool IS_VOWEL[256]; //static bool IS_CONSONANT[256]; static bool IS_UNVOICED[256]; static bool IS_IU[256]; static bool IS_AO[256]; #define ZERO_MEMORY(a) memset((a), 0, sizeof(a)) struct MORA { string consonant; string vowel; bool devocalization; MORA(const string& consonant, const string& vowel) : consonant(consonant), vowel(vowel), devocalization(false) { } string toString() { ostringstream oss; oss << consonant << (devocalization ? "(" : "") << vowel << (devocalization ? ")" : ""); return oss.str(); } bool isIu() { return vowel.size() && IS_IU[vowel[0]]; } bool isAo() { return vowel.size() && IS_AO[vowel[0]]; } bool isUnvoicedConsonant() { return consonant.size() && IS_UNVOICED[consonant[0]]; } bool isUnvoicedMora() { return consonant.size() && IS_UNVOICED[consonant[0]] && vowel.size(); } }; int main() { ZERO_MEMORY(IS_VOWEL); // ZERO_MEMORY(IS_CONSONANT); ZERO_MEMORY(IS_UNVOICED); ZERO_MEMORY(IS_IU); ZERO_MEMORY(IS_AO); IS_VOWEL['a'] = IS_VOWEL['i'] = IS_VOWEL['u'] = IS_VOWEL['e'] = IS_VOWEL['o'] = IS_VOWEL['\''] = true; IS_UNVOICED['k'] = IS_UNVOICED['s'] = IS_UNVOICED['p'] = IS_UNVOICED['h'] = IS_UNVOICED['t'] = true; IS_IU['i'] = IS_IU['u'] = true; IS_AO['a'] = IS_AO['o'] = true; string in; while (getline(cin, in) && in != "#"){ vector moras; //入力の分解 string last; for (int i = 0; i < in.size(); ++i){ if (last == "n" && !IS_VOWEL[in[i]]){ //撥音の特殊処理 moras.push_back(MORA(last, "")); last.clear(); } last += in[i]; if (IS_VOWEL[in[i]]){ //促音の特殊処理 if (last.size() >= 2 && last[0] == last[1]){ moras.push_back(MORA(last.substr(0, 1), "")); last.erase(0, 1); } moras.push_back(MORA(last.substr(0, last.size() - 1), last.substr(last.size() - 1))); last.clear(); } } if (last.size()){ //撥音の特殊処理 if (last == "n"){ moras.push_back(MORA(last, "")); } else { cerr << "err!!!!!" << endl; } } //母音チェック for (int i = 0; i < moras.size() - 1; ++i){ if (moras[i].isIu() && moras[i].isUnvoicedConsonant() && moras[i + 1].isUnvoicedConsonant()){ moras[i].devocalization = true; } } if (moras.back().isIu() && moras.back().isUnvoicedConsonant()){ moras.back().devocalization = true; } for (int i = 0; i < moras.size() - 1; ++i){ if (moras[i].isAo() && moras[i].vowel == moras[i + 1].vowel && moras[i].isUnvoicedConsonant() && moras[i + 1].isUnvoicedMora()){ moras[i].devocalization = true; } } //母音のない拍をまとめる int index = 0; while (index < moras.size() - 1){ if (moras[index].vowel.size() == 0){ moras[index + 1].consonant = moras[index].consonant + moras[index + 1].consonant; moras.erase(moras.begin() + index, moras.begin() + index + 1); } else { ++index; } } //はずし for (int i = 0; i < moras.size() - 1; ++i){ if (moras[i].devocalization && moras[i + 1].devocalization){ moras[i + 1].devocalization = false; } } //表示 for (int i = 0; i < moras.size(); ++i){ cout << moras[i].toString(); } cout << endl; } }