Notice : 内容無保証。禁無断転載。リンク不自由。

聞き間違いエンジンプロトタイプ まこぴー

c_wchar.h

#ifndef _c_wchar_h_
#define _c_wchar_h_

typedef class Cwchar* Pwchar ;
class Cwchar {
    union {
        struct {
            char    _0 ;
            char    _1 ;
        } ;
        short   _w ;
    } ;

public:
    Cwchar(char* pc = 0) ;
    void show(void) ;

    operator bool(void) ;
    operator char*(void) ;
    bool operator ==(char* pc) ;
} ;

#endif /* _c_wchar_h_ */

c_wchar.cpp

#include <stdio.h>
#include "c_wchar.h"

Cwchar::Cwchar(
    char* pc
):
    _0(pc ? pc[0] : 0),
    _1(pc ? pc[1] : 0)
{}

void Cwchar::show(void) {
    _0 ? putchar(_0), putchar(_1) : 0 ;
}

Cwchar::operator bool(void) {
    return _0 != 0 ;
}

Cwchar::operator char*(void) {
    return &_0 ;
}

bool Cwchar::operator ==(char* pc) {
    return pc ? (((Pwchar)pc)->_w == _w) : false ;
}

makop.cpp

#include <iostream>
#include "c_wchar.h"

using namespace std ;

static Pwchar  _[] = {
    (Pwchar)"あかさたなはまやらわがざだばぱゃ" "\0",
    (Pwchar)"いきしちにひみいりゐぎじぢびぴ"   "\0",
    (Pwchar)"うくすつぬふむゆるうぐずづぶぷゅ" "\0",
    (Pwchar)"えけせてねへめえれゑげぜでべぺ"   "\0",
    (Pwchar)"おこそとのほもよろをごぞどぼぽょ" "\0",
    0
} ;

static bool find(
    char*  pc,
    int&   bo,     // 母音
    int&   si      // 子音
){
    Pwchar  pwc = 0 ;
    int _bo = 0 ;

    while (pwc = _[_bo]){
        Cwchar  wc = "" ;
        int _si = 0 ;

        while (wc = pwc[_si]) {
            if (wc == pc) {
                bo = _bo ;
                si = _si ;
                return true ;
            }
            _si++ ;
        }
        _bo++ ;
    }

    return false ;
}

int main(
    int     argc,
    char*   argv[]
){
    Pwchar  originalString = Pwchar((2 <= argc) ? argv[1] : "まこぴー") ;

    for (Pwchar p = originalString ; *p ; p++) {
        int bo = 0 ;
        int si = 0 ;

        if (find(*p, bo, si)){
            for (Pwchar _bo = _[bo] ; *_bo ; _bo++) {
                for (Pwchar o = originalString ; *o ; o++){
                    if (o == p) {
                        _bo->show() ;
                    }else{
                        o->show() ;
                    }
                }
                cout << endl ;
            }
        }
        cout << endl ;
    }

    return 0 ;
}