Last active
January 4, 2016 21:39
-
-
Save KT-Yeh/8682557 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <cstdio> | |
#include <cstring> | |
using namespace std; | |
char APU[1000]; | |
int parsing (int front, int back) | |
{ | |
// 0:Mutant | |
// 1:Simple | |
// 2:Fully-Grown | |
// 3:Mutagenic | |
if (front==back && APU[front]=='A') return 1; | |
if (APU[back]=='B' && APU[back-1]=='A'){ // 判斷是否為Fully Grown | |
if (front == back-1) return 0; // 如果為"AB",那麼是Mutant | |
else if (parsing (front,back-2) != 0) return 2; | |
} | |
if (APU[front]=='B' && APU[back]=='A'){ // 判斷是否為Mutagenic | |
if (front+1 == back) return 0; // 如果為"BA",那麼是Mutant | |
else if (parsing (front+1,back-1) != 0) return 3; | |
} | |
return 0; // O不符合上面3種任一種型態,回傳0 | |
} | |
int main() | |
{ | |
int Case; | |
scanf("%d",&Case); | |
while (Case--){ | |
scanf("%s",APU); | |
int t = parsing (0,strlen(APU)-1); | |
switch (t){ | |
case 0: printf("MUTANT\n"); break; | |
case 1: printf("SIMPLE\n"); break; | |
case 2: printf("FULLY-GROWN\n"); break; | |
case 3: printf("MUTAGENIC\n"); break; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment