-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1157.cpp
More file actions
59 lines (54 loc) · 878 Bytes
/
1157.cpp
File metadata and controls
59 lines (54 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// 1157. 단어 공부
// 2019.05.14
#include<iostream>
#include<string>
using namespace std;
int arr[26]; // a~z의 개수 저장(대소문자 구분 없이)
int main()
{
int cnt = 0, big = 0, index;
string s;
cin >> s;
for (int i = 0; i < s.size(); i++)
{
if (s[i] >= 65 && s[i] <= 90) // 소문자
{
arr[s[i] - 65]++;
}
else if (s[i] >= 97 && s[i] <= 122) // 대문자
{
arr[s[i] - 97]++;
}
}
// 가장 많이 사용된 알파벳을 구하기
for (int i = 0; i < 26; i++)
{
if (arr[i] > big)
{
big = arr[i];
index = i;
}
}
// 가장 많이 사용된 알파벳이 여러개 인지 확인하기
for (int i = 0; i < 26; i++)
{
if (arr[i] == big)
{
cnt++;
if (cnt == 2)
{
break;
}
}
}
// 결과 출력
if (cnt == 2)
{
cout << "?" << endl;
}
else
{
cout << char(index + 65) << endl;
}
return 0;
}