티스토리 뷰

728x90

문제 링크

https://www.acmicpc.net/problem/25288

 

25288번: 영어 시험

aa(abba), ab(abba), ba(abba), bb(abba) 를 모두 부분 수열로 갖는다.

www.acmicpc.net

 

풀이

주어진 알파벳과 자릿수가 주어졌을 때, 중복 순열의 모든 케이스가 답이 될 수 있습니다. 각 자리에 어떤 알파벳이든 올 수 있어야 하므로 자리마다 모든 알파벳을 배치해줍시다.

예를 들어 길이가 4, 알파벳이 abc인 경우, abc / abc / abc / abc처럼 구성하면 가능한 모든 케이스를 고려할 수 있습니다.

 

 

정답 코드

// @BOJ ------------------------------------------
const fs = require('fs');
const stdin = fs.readFileSync('/dev/stdin').toString().split('\n');
const input = (() => {
  let line = 0;
  const input = () => stdin[line++];
  input.num = () => input().split(' ').map(Number);
  input.rows = l => Array(l).fill().map(input);
  input.rows.num = l => Array(l).fill().map(input.num);
  return input;
})();

// Solution -----------------------------------

const solution = function () {
  const n = +input();
  const letters = input();
  console.log(letters.repeat(n));
};

solution();
728x90
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함