#include #include /*使用する文字コードに応じて定義する*/ #define SHIFT_JIS /*#define EUC*/ /*#define UTF_8*/ /* 参考 http://ash.jp/code/code.htm */ /*次の一文字のバイト数を判定する*/ /*Shift-JIS用*/ #ifdef SHIFT_JIS int mozilen_hantei(const unsigned char* moziretu) { /*文字列終端*/ if (moziretu[0] == 0)return 0; /*次が文字列終端*/ if (moziretu[1] == 0)return 1; if ( ( (moziretu[0] >= 0x81 && moziretu[0] <= 0x9F) || (moziretu[0] >= 0xE0 && moziretu[0] <= 0xEF) ) && ( (moziretu[1] >= 0x40 && moziretu[1] <= 0x7E) || (moziretu[1] >= 0x80 && moziretu[1] <= 0xFC) ) )return 2; /*その他*/ return 1; } #endif /*EUC用*/ #ifdef EUC int mozilen_hantei(const unsigned char* moziretu) { /*文字列終端*/ if (moziretu[0] == 0)return 0; /*次が文字列終端*/ if (moziretu[1] == 0)return 1; if (moziretu[0] == 0x8E && (moziretu[1] >= 0xA1 && moziretu[1] <= 0xDF)) return 2; if ( (moziretu[0] >= 0xA1 && mozireut[0] <= 0xFE) && (moziretu[1] >= 0xA1 && moziretu[1] <= 0xFE) )return 2; if ( moziretu[0] == 0z8F && (moziretu[1] >= 0xA1 && moziretu[1] <= 0xFE) && (moziretu[2] >= 0xA1 && moziretu[2] <= 0xFE) && )return 3; /*その他*/ return 1; } #endif /*UTF-8用*/ #ifdef UTF_8 int mozilen_hantei(const unsigned char* moziretu) { int max, result; for (max = 0; max<6; max++) { if (moziretu[max] == 0)break; } result = 1; if ((moziretu[0] & 0x80) == 0x00)result = 1; else if ((moziretu[0] & 0xE0) == 0xC0 && max >= 2) { if ((moziretu[1] & 0xC0) == 0x80)result = 2; } else if ((moziretu[0] & 0xF0) == 0xE0 && max >= 3) { if ((moziretu[1] & 0xC0) == 0x80 && (moziretu[2] & 0xC0) == 0x80)result = 3; } else if ((moziretu[0] & 0xF8) == 0xF0 && max >= 4) { if ((moziretu[1] & 0xC0) == 0x80 && (moziretu[2] & 0xC0) == 0x80 && (moziretu[3] & 0xC0) == 0x80)result = 4; } else if ((moziretu[0] & 0xFC) == 0xF8 && max >= 5) { if ((moziretu[1] & 0xC0) == 0x80 && (moziretu[2] & 0xC0) == 0x80 && (moziretu[3] & 0xC0) == 0x80 && (moziretu[4] & 0xC0) == 0x80)result = 5; } else if ((moziretu[0] & 0xFE) == 0xFC && max >= 6) { if ((moziretu[1] & 0xC0) == 0x80 && (moziretu[2] & 0xC0) == 0x80 && (moziretu[3] & 0xC0) == 0x80 && (moziretu[4] & 0xC0) == 0x80 && (moziretu[5] & 0xC0) == 0x80)result = 6; } if (result>max)result = max; return result; } #endif int main(void) { std::string inputstr; std::string outputstr; const char* input; int* onelength; char* output; int i, j, len, inputmax; /*入力*/ std::getline(std::cin, inputstr); inputmax = inputstr.size(); input = inputstr.c_str(); onelength = new int[inputmax]; output = new char[inputstr.size() + 100]; /*半角と全角の判定*/ for (i = 0; i= 0; i--) { if (onelength[i]>0) { for (j = 0; j