-
<백준> 1157번: 단어 공부 (런타임 에러 (SyntaxError))유물/└ 백준 2022. 1. 22. 21:36728x90
👾
문제
https://www.acmicpc.net/problem/1157
풀이(오답)import fs from "fs"; const charList = fs.readFileSync("/dev/stdin").toString().trim(); const upperCharList = charList.toUpperCase().split(""); let countList = []; for (let i = 65; i <= 90; i++) { const alphabet = String.fromCharCode(i); let count = 0; upperCharList.forEach((char) => { char === alphabet ? (count += 1) : null; }); countList.push(count); } const maxNum = Math.max(...countList); let duplicated = 0; countList.forEach((char) => { char === maxNum ? (duplicated += 1) : null; }); duplicated === 1 ? console.log(maxNum) : console.log("?");
1. (공통) 런타임 에러 (SyntaxError)가 발생하였으나, 아직 해결하지 못했습니다.
2. (line 7~14) 알파벳이 반복되는 횟수를 배열로 저장하였습니다.
3. (line 16) Math.max 메서드를 활용하여 최대 반복 횟수를 찾았습니다.
4. (line 18~24) 최대 반복 횟수에 중복이 있는지 판단하여, 판단 결과에 따라 다른 값을 출력합니다.
728x90'유물 > └ 백준' 카테고리의 다른 글
<백준> 2908번: 상수 (0) 2022.02.04 <백준> 1152번: 단어의 개수 (0) 2022.02.03 <백준> 2675번: 문자열 반복 (런타임 에러 (SyntaxError)) (0) 2022.01.21 <백준> 10809번: 알파벳 찾기 (0) 2022.01.20 <백준> 11720번: 숫자의 합 (0) 2022.01.18