首页 > 编程语言 > 详细

1003 我要通过! (20分) -java

时间:2020-02-13 13:38:22      阅读:67      评论:0      收藏:0      [点我收藏+]
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int len = Integer.parseInt(in.nextLine());
        String[] strings = new String[len];
        for (int i = 0; i < len; i++) {
            strings[i] = in.nextLine();
        }

        int k;
        boolean flag;

        for (String s : strings) {
            k = 0;
            flag = true;
            int[] a = new int[3];
            char[] chars = s.toCharArray();
            for (char ch : chars) {
                if (ch == ‘A‘) {
                    a[k]++;
                } else if (ch == ‘P‘ && k == 0) {
                    k = 1;
                } else if (ch == ‘T‘ && k == 1) {
                    k = 2;
                } else {
                    flag = false;
                }
            }
            /**
             * 包含的每个字符必须是p a t中的某一个
             * p在t前
             * p t各一个,至少一个a
             * n0*n1=n2
             */
            if (flag && k == 2 && a[1] >= 1 && a[0] * a[1] == a[2]) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
}

  

 

1003 我要通过! (20分) -java

原文:https://www.cnblogs.com/zxqSS/p/12264846.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!