몸과 마음이 건전한 SW 개발자

Softeer Level 2 X marks the Spot {언어 : JavaScript} 본문

알고리즘

Softeer Level 2 X marks the Spot {언어 : JavaScript}

스위태니 2024. 2. 13. 23:27

문제 링크

https://softeer.ai/practice/7703

 

Softeer - 현대자동차그룹 SW인재확보플랫폼

 

softeer.ai

정답 코드

const readline = require("readline");

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

let numberOfPairs = 0; // 문자열 쌍의 개수 N
let currentLine = 0; // 현재 처리 중인 입력 줄
const isValid = ["x", "X"];
const result = []; // 결과를 저장할 배열

rl.on("line", (line, index) => {
    if (index === 0) {
        // 첫 번째 줄에서는 문자열 쌍의 개수 N을 받습니다.
        numberOfPairs = parseInt(line);
    } else {
        const string = line.split(" ")
        const leftString = string[0]
        const rightString = string[1]
        const lenString = leftString.length
        for (let jdx = 0; jdx < lenString; jdx++) {
            // 문자열이 array = ["x", "X"]에 속하는지 확인
            if (isValid.includes(leftString[jdx])) {
                // 결과값에 저장
                // result += rightString[jdx]보다 이것이 더 빠르다.
                result.push(rightString[jdx].toUpperCase())
            }
        }
        if (index === numberOfPairs) {
            // 모든 문자열 쌍을 받았다면 입력을 종료합니다.
            rl.close();
        }
    }
    currentLine++;
}).on("close", () => {
    // 입력 받기를 완료한 후의 로직을 여기에 작성합니다.
    console.log(result.join(""));
    process.exit(0);
});

풀이 방법

https://sound-programming.tistory.com/77

 

Softeer Level 2 X marks the Spot {언어 : Python}

문제 링크 https://softeer.ai/practice/7703 Softeer - 현대자동차그룹 SW인재확보플랫폼 softeer.ai 정답 코드 import sys input = sys.stdin.readline result = [] N = int(input()) for _ in range(N): left, right = input().split() # 앞 뒤에

sound-programming.tistory.com

  • 파이썬으로 푼 방식과 똑같으나 자바스크립트로 풀었다.

느낀점

  • 입력 방식은 외워야 할 부분이 많다.
  • 기본적인 내장 함수에 대해서 정리할 수 있는 시간이 될 것 같다.