zoukankan      html  css  js  c++  java
  • codeForces_MinusAndMinusGivePlus

    import java.util.LinkedList;
    import java.util.Queue;
    import java.util.Scanner;
    
    /**
     * @author chenjiena
     * @version 1.0
     * @created 2019-06-01 18:15
     **/
    public class MinusAndMinusGivePlus {
    
        public static void main(String[] arg){
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            Queue<String> result = new LinkedList<String>();
    
            for (int i=0;i<n;i++){
                Queue<Character> q1 = new LinkedList<Character>();
                Queue<Character> q2 = new LinkedList<Character>();
                int j = 0,k = 0;
                String s1 = in.next();
                do {
                    q1.offer(s1.charAt(j));
                    ++j;
                }while (j < s1.length() && s1.charAt(j) != '
    ');
    
                String s2 = in.next();
                do {
                    q2.offer(s2.charAt(k));
                    ++k;
                }while (k < s2.length() && s2.charAt(k) != '
    ');
    
                while (!q1.isEmpty() && !q2.isEmpty()){
                     if (q1.peek() != q2.peek()){
                         if (q1.peek() == '-'){
                             q1.poll();
                             if (!q1.isEmpty() && !q2.isEmpty()) {
                                 if (q1.peek() == '-') {
                                     q1.poll();
                                     q2.poll();
                                 }
                             }
                         }else {
                             q2.poll();
                             if (q2.peek() == '-'){
                                 q1.poll();
                                 q1.poll();
                             }
                         }
                     }else {
                         q1.poll();
                         q2.poll();
                     }
                }
    
                if (q1.isEmpty() && q2.isEmpty()){
                    result.offer("YES");
                }else {
                    result.offer("NO");
                }
            }
    
            while (!result.isEmpty()){
                System.out.println(result.poll());
            }
        }
    }
    

      

  • 相关阅读:
    java:第三章
    java:第一章
    java:第二章
    复制a.jpg到b.jpg
    安卓事件大全
    安卓事件
    read输入流与writer输出流的对比
    第五章:循环结构
    第三章:选择结构(一)
    第二章:变量,数据类型和运算符
  • 原文地址:https://www.cnblogs.com/cjn123/p/11025747.html
Copyright © 2011-2022 走看看