Created
November 14, 2013 05:18
-
-
Save kashi/7461803 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
http://nabetani.sakura.ne.jp/hena/ord14linedung/ | |
*/ | |
#include <stdio.h> | |
#include <string.h> | |
int fight(char *s) | |
{ | |
int i, n, score, monster[6], tbl[0x7f]; | |
tbl['B'] = 0; | |
tbl['D'] = 1; | |
tbl['F'] = 2; | |
tbl['H'] = 3; | |
tbl['J'] = 4; | |
tbl['L'] = 5; | |
tbl['a'] = 10; | |
tbl['c'] = 11; | |
tbl['e'] = 12; | |
tbl['g'] = 13; | |
tbl['i'] = 14; | |
tbl['k'] = 15; | |
for (i=0; i<6; i++) monster[i] = 0; | |
for (i=0; i<strlen(s); i++) { | |
if (tbl[*(s+i)] < 10) monster[tbl[*(s+i)]]++; | |
} | |
score = 0; | |
for (i=0; i<strlen(s); i++) { | |
if (tbl[*(s+i)] >= 10) { | |
n = tbl[*(s+i)] - 10; | |
while (monster[n] > 0) { | |
score += monster[n]; | |
monster[n] = 0; | |
n = (n + 1) % 6; | |
} | |
} | |
} | |
return score; | |
} | |
void test(char *s, char *expected) | |
{ | |
char got[3]; | |
sprintf(got, "%d", fight(s)); | |
if (strcmp(got, expected) == 0) { | |
printf("%s : OK\n", s); | |
} else { | |
printf("%s : NG : got=%s, expected=%s\n", s, got, expected); | |
} | |
} | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment