PAT-B-1003-C#描述

 
 
using System;

namespace PAT
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] list = new string[n];
            int i = 0;
            for (i = 0; i < n; ++i)
            {
                list[i] = Console.ReadLine();
            }
            for (int j = 0; j < n; ++j)
            {
                Console.WriteLine(IsTrue(list[j]));
            }
        }
      
      static string IsTrue(string str)
        {
            int nP = 0, nA = 0, nT = 0;
            int length = str.Length;
            int indexP = 0, indexT = 0;
            for (int i = 0; i < length; ++i)
            {
                if (str[i] != 'P' && str[i] != 'A' && str[i] != 'T' && str[i] != ' ')
                    return "NO";
                if (str[i] == 'P')
                {
                    nP++;
                    if (nP > 1)
                        return "NO";
                    indexP = i;
                    continue;
                }
                if (str[i] == 'A')
                {
                    nA++;
                    continue;
                }
                if (str[i] == 'T')
                {
                    nT++;
                    if (nT > 1)
                        return "NO";
                    indexT = i;
                    continue;
                }
            }
            if (nP + nA + nT == length && nA > 0 && nP == 1 && nT == 1 && (indexT - indexP) > 1 && indexP * (indexT - indexP - 1) == length - indexT - 1)
                return "YES";
            return "NO";
        }
    }
}


发布了14 篇原创文章 · 获赞 1 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/m0_37302219/article/details/79471968
今日推荐