백준 GOLD 5(A와 B) - #12904

image

  • 사용 언어 : javascript

  • 해결 날짜 : 2023-02-15

  • 해결 방법 :

    • S에서 T로 추가하는게 아닌 T에서 S로 제거하면서 체크
    • T의 마지막이 A면 pop()
    • T의 마지막이 B면 pop() 후 뒤집기
  • 회고 :

    • x
  • 코드

    const fs = require('fs');
    const filePath = process.platform === 'linux' ? '/dev/stdin' : '../input.txt';
    const input = fs.readFileSync(filePath).toString().trim();
    
    solution(input);
    
    function solution(props) {
      const [S, T] = props.split('\n').map((prop) => prop.split(''));
    
      while (S.length !== T.length) {
        if (T.at(-1) === 'A') {
          T.pop();
        } else {
          T.pop();
          T.reverse();
        }
      }
    
      console.log(S.toString() === T.toString() ? 1 : 0);
    }
    
  • 출처: 백준