문제

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

걸린 시간

-

풀이

TypeScript

import * as fs from "fs";

const filePath: string = process.platform === 'linux' ? '/dev/stdin' : './input';

const stdin: string[] = fs.readFileSync(filePath).toString().split('\n');
const input: Function = ((): Function => { 
  let line: number = 0;
  return (): string => stdin[line++];
})();

const num: Array<number> = input().split(' ').map(Number);

interface counter_dict {
  [key: number]: number;
}

const num_dict: counter_dict = {};
for(let i of num){
  if(num_dict[i] === undefined) num_dict[i] = 1;
  else num_dict[i]++;
}

const solve: Function = () => {
  let max_num: number = 0;
  for(let [k, v] of Object.entries(num_dict)){
    max_num = Math.max(max_num, parseInt(k));
    if(v === 3) return 10000+parseInt(k)*1000;
    else if(v === 2) return 1000+parseInt(k)*100;
  }
  return max_num*100;
}

console.log(solve());

새롭게 알게 된 것들 나열

  • map 메서드를 이용한 배열 내 자료형 변환
  • typescript interface 를 가지는 dictionary 사용
  • dictionary 순회 방법

'Baekjoon' 카테고리의 다른 글

Baekjoon 1904번 01타일  (0) 2022.03.16
Baekjoon 10799번 쇠막대기  (0) 2022.03.14
Baekjoon 3221번 개미의 이동  (0) 2021.09.30
Baekjoon 11725번 트리의 부모 찾기  (0) 2021.09.17
Baekjoon 13549번 숨바꼭질 3  (0) 2021.09.12

댓글