File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ # [ Bronze II] 가장 많은 글자 - 1371
2
+
3
+ [ 문제 링크] ( https://www.acmicpc.net/problem/1371 )
4
+
5
+ ### 성능 요약
6
+
7
+ 메모리: 14468 KB, 시간: 140 ms
8
+
9
+ ### 분류
10
+
11
+ 구현, 문자열
12
+
13
+ ### 제출 일자
14
+
15
+ 2024년 4월 4일 21:29:41
16
+
17
+ ### 문제 설명
18
+
19
+ <p >영어에서는 어떤 글자가 다른 글자보다 많이 쓰인다. 예를 들어, 긴 글에서 약 12.31% 글자는 e이다.</p >
20
+
21
+ <p >어떤 글이 주어졌을 때, 가장 많이 나온 글자를 출력하는 프로그램을 작성하시오.</p >
22
+
23
+ ### 입력
24
+
25
+ <p >첫째 줄부터 글의 문장이 주어진다. 글은 최대 50개의 줄로 이루어져 있고, 각 줄은 최대 50개의 글자로 이루어져 있다. 각 줄에는 공백과 알파벳 소문자만 있다. 문장에 알파벳은 적어도 하나 이상 있다.</p >
26
+
27
+ ### 출력
28
+
29
+ <p >첫째 줄에 가장 많이 나온 문자를 출력한다. 여러 개일 경우에는 알파벳 순으로 앞서는 것부터 모두 공백없이 출력한다.</p >
30
+
Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+ import java .util .*;
3
+ public class Main {
4
+ public static void main (String [] args ) throws IOException {
5
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
6
+ BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System .out ));
7
+ int [] al = new int [26 ];
8
+ br .lines ()
9
+ .flatMapToInt (CharSequence ::chars )
10
+ .filter (c -> c != ' ' )
11
+ .forEach (c -> al [c -97 ]++);
12
+ int max = Arrays .stream (al ).max ().orElse (0 );
13
+ for (int i =0 ; i < al .length ; i ++) {
14
+ if (max == al [i ])
15
+ bw .write ((char )(i +97 ));
16
+ }
17
+ bw .flush ();
18
+ bw .close ();
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments