monster.c(2)

問題はこちら
http://nabetani.sakura.ne.jp/hena/ord14linedung/

他の解答例はこちら
http://qiita.com/Nabetani/items/0597bd3af481e5834ae1

このコードはモンスターを武器に変えていく方針で作りました。

武器を拾って、その武器で倒せるモンスター全てを武器化。
使った武器は用済みなので、全て、武器でもモンスターでもない`'X'`に置き換えます。
そして、また武器を拾いに行きます。

```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int gpos(const char *s, const char c)
{
    return strchr(s, c)-s;
}

int solve(const char *in)
{
    const char  M[] = "BDFHJL",
                A[] = "acegik",
                G[] = "cegika";
    int r = 0;
    char *f = strdup(in);

    for( int i=0; f[i]; i++ ) {
        char a = f[i];
        int ap = gpos(A,f[i]);
        if( ap < 0 ) continue;
        i = -1;
        for( int j=0; f[j]; j++ ) {
            if( f[j] == a ) f[j] = 'X';
            int mp = gpos(M,f[j]);
            if( mp == ap ) {
                f[j] = G[mp];
                r++;
            }
        }
    }
    free(f);
    return r;
}

void test(const char *in, const char *a)
{
    const int r = solve(in);
    printf("%d\t%s\n",r,(r==atoi(a)) ? "ok" : "***NG***");
}

int main()
{
/*0*/ test( "gLDLBgBgHDaD", "6" );    
/*1*/ test( "DBcDLaLgDBH", "6" );    
/*2*/ test( "JJca", "0" );    
/*3*/ test( "FJDLBH", "0" );    
/*4*/ test( "HJBLFDg", "6" );    
/*5*/ test( "HBaDLFJ", "6" );    
/*6*/ test( "DJaHLB", "2" );    
/*7*/ test( "gDLHJF", "3" );    
/*8*/ test( "cJFgLHD", "5" );    
/*9*/ test( "FFBJaJJ", "1" );    
/*10*/ test( "FJeJFBJ", "2" );    
/*11*/ test( "iJFFJJB", "3" );    
/*12*/ test( "JBJiLFJF", "5" );    
/*13*/ test( "JDiFLFBJJ", "8" );    
/*14*/ test( "BDFDFFDFFLLFFJFDBFDFFFFDDFaDBFFB", "28" );    
/*15*/ test( "DDFBFcBDFFFFFFLBFDFFBFLFDFDJDFDF", "24" );    
/*16*/ test( "FDLBFDDBFFFeFFFFFDFBLDDFDDFBFFJF", "16" );    
/*17*/ test( "FDBFFLFDFFDBBDFFBJDLFgDFFFDFFDFF", "0" );    
/*18*/ test( "FDiFLDFFFFBDDJDDBFBFDFFFBFFDFLFF", "31" );    
/*19*/ test( "FDFDJBLBLBFFDDFFFDFFFFFDDFBkFDFF", "30" );    
/*20*/ test( "HBkFFFFHBLH", "3" );    
/*21*/ test( "FBHHFFFHLaB", "2" );    
/*22*/ test( "LFHFBBcHFHF", "0" );    
/*23*/ test( "LFBHFFeFHBH", "7" );    
/*24*/ test( "LgFHHHBFBFF", "3" );    
/*25*/ test( "FFiFHBHLBFH", "0" );    
/*26*/ test( "BFHHFFHBeFLk", "10" );    
/*27*/ test( "FHFaBBHFHLFg", "5" );    
/*28*/ test( "FFgacaFg", "0" );    
/*29*/ test( "JHDaDcBJiiHccBHDBDH", "9" );    
/*30*/ test( "FHJJLckFckFJHDFF", "12" );    
/*31*/ test( "DeDHJHDFHJBLHDLLDHJLBDD", "22" );    
/*32*/ test( "gJLLLJgJgJLJL", "0" );    
/*33*/ test( "DaaaDDD", "0" );    
/*34*/ test( "HFeJFHiBiiBJeJBBFFB", "9" );    
/*35*/ test( "FJFFJDBHBHaLJBHJHDLHkLLLFFFgJgHJLHkJkB", "32" );    
/*36*/ test( "giFLBiBJLLJgHBFJigJJJBLHFLDLL", "23" );    
/*37*/ test( "cgkLJcLJJJJgJc", "2" );    
/*38*/ test( "LDFHJHcFBDBLJBLFLcFJcDFBL", "22" );    
/*39*/ test( "JJHHHkHJkHLJk", "1" );    
/*40*/ test( "kHHBBaBgHagHgaHBBB", "11" );    
/*41*/ test( "HDBFFDHHHDFLDcHHLFDcJD", "20" );    
/*42*/ test( "HFFFHeFFee", "7" );    
/*43*/ test( "gLLDHgDLgFL", "1" );    
/*44*/ test( "JJJBBaBBHBBHaLBHJ", "7" );    
/*45*/ test( "FBFBgJBDBDgF", "0" );    
/*46*/ test( "LLLLakakLakLL", "7" );    
/*47*/ test( "HeJHeJe", "0" );    
/*48*/ test( "LDFLBLLeBLDBBFFBLFBB", "4" );  
    return 0;
}
```