728x90
반응형
1371번: 가장 많은 글자
첫째 줄부터 글의 문장이 주어진다. 글은 최대 50개의 줄로 이루어져 있고, 각 줄은 최대 50개의 글자로 이루어져 있다. 각 줄에는 공백과 알파벳 소문자만 있다. 문장에 알파벳은 적어도 하나 이
www.acmicpc.net
조건문에 입력 넣기
- 제목
가장 많은 글자
- 조건
시간 제한 : 2 초
메모리 제한 : 128 MB
- 문제
영어에서는 어떤 글자가 다른 글자보다 많이 쓰인다. 예를 들어, 긴 글에서 약 12.31% 글자는 e이다.
어떤 글이 주어졌을 때, 가장 많이 나온 글자를 출력하는 프로그램을 작성하시오.
- 입력
첫째 줄부터 글의 문장이 주어진다. 글은 최대 50개의 줄로 이루어져 있고, 각 줄은 최대 50개의 글자로 이루어져 있다. 각 줄에는 공백과 알파벳 소문자만 있다. 문장에 알파벳은 적어도 하나 이상 있다.
- 출력
첫째 줄에 가장 많이 나온 문자를 출력한다. 여러 개일 경우에는 알파벳 순으로 앞서는 것부터 모두 공백없이 출력한다.
예제 입력1 | 예제 출력1 |
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 |
예제 입력2 | 예제 출력2 |
baekjoon online judge | eno |
예제 입력3 | 예제 출력3 |
abc a | a |
예제 입력4 | 예제 출력4 |
abc ab |
ab |
예제 입력5 | 예제 출력5 |
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 |
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define endl '\n'
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string str;
int alphabet[26], max = -1;
for(int n = 0 ; n < 26 ; n++) alphabet[n] = 0;
while(getline(cin, str)){
for(int n = 0 ; n < str.size() ; n++) alphabet[str[n] - 'a']++;
}
for(int n = 0 ; n < 26 ; n++){
if(max < alphabet[n]) max = alphabet[n];
}
for(int n = 0 ; n < 26 ; n++){
if(max == alphabet[n]) cout << (char)('a' + n);
}
cout << endl;
return 0;
}
728x90
반응형
'Problem Solving > BaekJoon' 카테고리의 다른 글
[BOJ/백준] 24957 - Loop of Chocolate (0) | 2022.09.02 |
---|---|
[BOJ/백준] 17352 - 여러분의 다리가 되어 드리겠습니다! (0) | 2022.09.01 |
[BOJ/백준] 2170 - 선 긋기 (0) | 2022.08.31 |
[BOJ/백준] 6318 - Box of Bricks (0) | 2022.08.27 |
[BOJ/백준] 1225 - 이상한 곱셈 (0) | 2022.08.25 |