程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> uva 620 Cellular Structure (水題)

uva 620 Cellular Structure (水題)

編輯:C++入門知識

uva 620 Cellular Structure (水題)


uva 620 Cellular Structure

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.

Input
A integer n being a number of cellular chains to test, and then n consecutive lines containing chains of tested organisms.

Output
For each tested chain give (in separate lines) proper answers:

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.

Sample Input

4
A
AAB
BAAB
BAABA

Sample Output

SIMPLE
FULLY-GROWN
MUTANT
MUTAGENIC

題目大意:有三種分裂方式:

1)在空的情況下,生成A—>SIMPLE;

2)在不空的情況下,在兩邊生成B 和 A–>MUTAGENIC;

3)在不空的情況下,在右邊生成AB–>FULLY-GROWN;

當三種情況都不滿足輸出 MUTANT。

題目要求求出最後一種分裂方式。

解題思路:先判斷字符串的長度:為1時,輸出SIMPLE;為偶數時,輸出MUTANT;為奇數時,從後往前遍歷,若當前字母為B判斷FULLY-GROWN方法,為A時判斷MUTAGENIC方法,判斷不滿足跳出循環輸出MUTANT。從後往前遍歷到的第一種方法就是酒後一種分裂方式。

#include 
#include 
#include 
#include 
#include 
#define N 10005
using namespace std;
typedef long long ll;
char s[N];
int main() {
    int T;
    scanf("%d", &T);    
    while (T--) {
        scanf("%s", s);
        int len = strlen(s);
        if (len == 1) {
            printf("SIMPLE\n");
            continue;
        }
        else if (len % 2 == 0) {
            printf("MUTANT\n");
            continue;
        }
        int flag = 1;
        int first = 0, last = len - 1;
        while (first != last) {
            if (s[last] == 'B') {
                if (s[last - 1] != 'A') {
                    flag = 0;
                    break;
                }
                else {
                    if (flag == 1) flag = 2;
                    last -= 2;
                }
            } else if (s[last] == 'A') {
                if (s[first] != 'B') {
                    flag = 0;
                    break;
                }
                else {
                    if (flag == 1) flag = 3;
                    last--;
                    first++;
                }
            }
        }
        if (flag == 1 || flag == 0) printf("MUTANT\n");
        else if (flag == 2) printf("FULLY-GROWN\n");
        else if (flag == 3) printf("MUTAGENIC\n");
    }
    return 0;
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved