1371번: 가장 많은 글자백준/문제2024. 1. 5. 12:56
Table of Contents
문제 출처 : https://www.acmicpc.net/problem/1371
언어 : Kotlin
문제 설명 :
영어에서는 어떤 글자가 다른 글자보다 많이 쓰인다. 예를 들어, 긴 글에서 약 12.31% 글자는 e이다.
어떤 글이 주어졌을 때, 가장 많이 나온 글자를 출력하는 프로그램을 작성하시오.
입력 :
첫째 줄부터 글의 문장이 주어진다. 글은 최대 50개의 줄로 이루어져 있고, 각 줄은 최대 50개의 글자로 이루어져 있다. 각 줄에는 공백과 알파벳 소문자만 있다. 문장에 알파벳은 적어도 하나 이상 있다.
출력 :
첫째 줄에 가장 많이 나온 문자를 출력한다. 여러 개일 경우에는 알파벳 순으로 앞서는 것부터 모두 공백없이 출력한다.
제한 사항 :
- 시간 제한 : 2초
- 메모리 제한 : 128MB
입출력 예 :
입력 | 출력 |
english is a west germanic language originating in england and is the first language for most people in the united kingdom the united states canada australia new zealand ireland and the anglophone caribbean it is used extensively as a second language and as an official language throughout the world especially in common wealth countries and in many international organizations |
a |
baekjoon online judge | eno |
abc ab |
ab |
amanda forsaken bloomer meditated gauging knolls betas neurons integrative expender commonalities latins antidotes crutched bandwidths begetting prompting dog association athenians christian ires pompousness percolating figured bagatelles bursted ninth boyfriends longingly muddlers prudence puns groove deliberators charter collectively yorks daringly antithesis inaptness aerosol carolinas payoffs chumps chirps gentler inexpressive morales |
e |
풀이 :
import java.io.BufferedWriter
import java.io.OutputStreamWriter
fun main() = with(System.`in`.bufferedReader()) {
val bw = BufferedWriter(OutputStreamWriter(System.out))
val alphabet = IntArray(26) { 0 }
var max = 0
while (true) {
val input = readLine() ?: break
input.forEach {
if (it != ' ') {
alphabet[it - 'a']++
if (max < alphabet[it - 'a']) max = alphabet[it - 'a']
}
}
}
alphabet.forEachIndexed { index, i ->
if (max == i) bw.write("${'a' + index}")
}
bw.flush()
bw.close()
}
'백준 > 문제' 카테고리의 다른 글
10822번: 더하기 (0) | 2024.01.05 |
---|---|
5218번: 알파벳 거리 (1) | 2024.01.05 |
9996번: 한국이 그리울 땐 서버에 접속하지 (1) | 2024.01.04 |
1251번: 단어 나누기 (2) | 2024.01.03 |
4659번: 비밀번호 발음하기 (2) | 2024.01.03 |
@스몰스테핑 :: 작은 발걸음
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!