#9
アルファベット文字列を入力し、「DENDENMUSHI」を含む文字列の時、
『jyuri!』を出力、含まない文字列の時は『not found!』と出力せよ。
入力:アルファベット文字列
出力:DENDENMUSHIを含む文字列 → jyuri!
DENDENMUSHIを含まない文字列→not found!
状態遷移図
プログラム
#include<stdio.h>
int move(char string[]);
int q[12][26] = {
/* a b c d e f g h i j k l m n o p q r s t u v w x y z */
/* q00 */{ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
/* q01 */{ 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
/* q02 */{ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
/* q03 */{ 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
/* q04 */{ 0, 0, 0, 1, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
/* q05 */{ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
/* q06 */{ 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
/* q07 */{ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0},
/* q08 */{ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0},
/* q09 */{ 0, 0, 0, 1, 0, 0, 0,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
/* q10 */{ 0, 0, 0, 1, 0, 0, 0, 0,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
/* q11 */{11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11}
};
int main(void){
char string[100];int i;
scanf("%s", string);
i = move(string);
if(i == 1){printf("jyuri!");
}
else{printf("not found!");
}
/* scanf("%d"); */return 0;
}
int move(char string[]){
int i = 0;int j = 0;
for(i=0; string[i] != '\0'; i++){
j = q[j][(int)(string[i]-'a')];
printf("jyoutai: %d\n",j);
if(j==11){
return 1;
}
}
return 0;}