zoukankan      html  css  js  c++  java
  • test

    public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            while (scanner.hasNextLine()) {
                String input = scanner.nextLine();
                if (input == null || input.length() == 0) {
                    System.out.println(0);
                    continue;
                }
                boolean nextIsChar = true;
                boolean nextIsCommand = false;
                boolean onlyNOTCommand = false;
                boolean flag = true;
                String[] element = input.split(" ");
                for (String temp : element) {
                    if (temp.length() == 1 && (Character.isLowerCase(temp.charAt(0)))) {
                        if (nextIsChar) {
                            nextIsChar = false;
                            nextIsCommand = true;
                            onlyNOTCommand = false;
                            continue;
                        } else {
                            System.out.println(0);
                            flag = false;
                            break;
                        }
                    } else if (temp.length() > 1) {
                        if (nextIsCommand) {
                            if (!onlyNOTCommand && temp.equals("AND")) {
                                nextIsChar = true;
                                nextIsCommand = false;
                                continue;
                            } else if (!onlyNOTCommand && temp.equals("OR")) {
                                nextIsChar = true;
                                onlyNOTCommand = true;
                                continue;
                            } else if (temp.equals("NOT")) {
                                nextIsChar = true;
                                nextIsCommand = false;
                                onlyNOTCommand = false;
                                continue;
                            } else {
                                System.out.println(0);
                                flag = false;
                                break;
                            }
                        } else {
                            System.out.println(0);
                            flag = false;
                            break;
                        }
    
                    }
                    flag = false;
                    System.out.println(0);
                    break;
                }
                if (flag) {
                    System.out.println(1);
                }
            }
        }
  • 相关阅读:
    [Qt] 事件机制(四)
    shell专题(六):条件判断
    最小生成树
    373. Find K Pairs with Smallest Sums
    gradle代理设置
    266. Palindrome Permutation
    53. Maximum Subarray
    378. Kth Smallest Element in a Sorted Matrix
    240. Search a 2D Matrix II
    74. Search a 2D Matrix
  • 原文地址:https://www.cnblogs.com/ustc-anmin/p/12615144.html
Copyright © 2011-2022 走看看