codeForces_MinusAndMinusGivePlus

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) != '\n');

            String s2 = in.next();
            do {
                q2.offer(s2.charAt(k));
                ++k;
            }while (k < s2.length() && s2.charAt(k) != '\n');

            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());
        }
    }
}

  

 

上一篇:菜鸡的2020年腾讯实习笔试


下一篇:leetcode [284]Peeking Iterator