본문 바로가기

Baekjoon(C++)

[C++]백준 알고리즘 1157번

풀이는 아래와 같다.

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
#include <iostream>
#include <string>
 
int count[26];
 
using namespace std;
 
int main()
{
    string word;
    cin >> word;
 
    for(int i=0; i<word.length(); i++){
        if(word[i] >= 'A' && word[i] <= 'Z'){
            count[word[i]-'A']++;
        }else{
            count[word[i]-'a']++;
        }
    }
    int max_letter=0;
    int max=0;
    for(int i=0; i<26; i++){
        if(max < count[i]){
            max = count[i];
            max_letter = i;
        }
    }
    for(int i=0; i<26; i++){
        if(max == count[i] && max_letter != i){
            cout << '?' << '\n';
            break;
        }
        if(i ==25){
            char output = max_letter + 'A';
            cout << output << '\n';
        }
    }
    
    return 0;
}
 
 
cs

 

반응형

'Baekjoon(C++)' 카테고리의 다른 글

[C++]백준 알고리즘 1316번  (0) 2021.07.14
[C++]백준 알고리즘 2908번  (0) 2021.07.14
[C++]백준 알고리즘 10809번  (0) 2021.07.14
[C++]백준 알고리즘 19532번  (0) 2021.07.11
[C++]백준 알고리즘 1463번  (0) 2021.07.11