- import java.io.BufferedInputStream;
- import java.util.Scanner;
- import java.util.Stack;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(new BufferedInputStream(System.in));
- Stack<Character> stack = new Stack<Character>();
- while (sc.hasNext()) {
- stack.empty();
- int n = sc.nextInt();
- String inSeq = sc.next();
- String outSeq = sc.next();
- char opSeq[] = new char[inSeq.length() * 2 + 1];// record the operates of the exchanging
- int inPos = 0;
- int outPos = 0;
- int seqPos = 0;
- while (outPos < n) {
- if (!stack.isEmpty() && stack.peek() == outSeq.charAt(outPos)) {
- outPos++;
- // if the stack is not empty and the top of the stack fit the out seq
- stack.pop();
- opSeq[seqPos++] = 'o';
- } else if (inPos < n) {
- stack.push(inSeq.charAt(inPos++));
- opSeq[seqPos++] = 'i';
- } else {// if we can push or pop,then we cant finish the exchanging
- break;
- }
- }
- if (stack.isEmpty()) {// if stack is empty means that the exchanging is success
- System.out.println("Yes.");
- for (int i = 0; i < inSeq.length() * 2; i++) {
- if (opSeq[i] == 'i') {
- System.out.println("in");
- } else {
- System.out.println("out");
- }
- }
- } else {
- System.out.println("No.");
- }
- System.out.println("FINISH");
- stack.clear();
- }
- }
- }
C还需要自己写个栈,JAVA就简单多了,一开始没有clearstack出了一次WA,其实还是挺简单的。。