A chain of connected cells of two types A and B composes a cellular structure of some microorganisms of species APUDOTDLS.
If no mutation had happened during growth of an organism, its cellular chain would take one of the following forms:
simple stage O = A fully-grown stage O = OAB mutagenic stage O = BOA
Sample notation O = OA means that if we added to chain of a healthy organism a cell A from the right hand side, we would end up also with a chain of a healthy organism. It would grow by one cell A.
A laboratory researches a cluster of these organisms. Your task is to write a program which could find out a current stage of growth and health of an organism, given its cellular chain sequence.
SIMPLE for simple stage FULLY-GROWN for fully-grown stage MUTAGENIC for mutagenic stage MUTANT any other (in case of mutated organisms)
If an organism were in two stages of growth at the same time the first option from the list above should be given as an answer.
4 A AAB BAAB BAABA
SIMPLE FULLY-GROWN MUTANTMUTAGENIC
序列可以从空开始变化,总共有三种形式,直接递归处理就好了。
#include<iostream> #include<algorithm> #include<math.h> #include<cstdio> #include<string> #include<string.h> using namespace std; int t, n; char s[10000]; int check(int q, int h) { if (q == h&&s[q] == 'A') return 1; else if (h <= q + 1) return 0; if (s[q] == 'B'&&s[h] == 'A') return check(q + 1, h - 1); if (s[h] == 'B'&&s[h - 1] == 'A') return check(q, h - 2); return 0; } int main(){ cin >> t; while (t--) { scanf("%s", s); n = strlen(s) - 1; if (s[0] == 'A'&&!n) cout << "SIMPLE" << endl; else if (check(0, n)) if (s[n] == 'B') cout << "FULLY-GROWN" << endl; else cout << "MUTAGENIC" << endl; else cout << "MUTANT" << endl; } return 0; }