[c++/알고리즘] 백준 1157번

corncheese·2021년 7월 14일
0

알고리즘문제풀이

목록 보기
3/31

// 백준 1157번

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){

    string a;
    char A;
    int max=-2147000000, index[26] = {0,}, cnt=0;

    cin >> a;

    transform(a.begin(), a.end(), a.begin(), ::toupper);

    for(int i=0; i<=a.length(); i++){
        index[a[i]-65]++;
    }

    for(int i=0; i<26; i++){
        if(index[i] == max) {
            max = index[i];
            cnt++;
        }
        if(index[i] > max){
            max = index[i];
            A = i+65;
            cnt = 0;
        }
    }
    if(cnt == 0) cout << A << endl;
    else cout << "?" << endl;

}
  • c++ string STL : 문자열 대소문자 변환하기 - toupper
    transform(String.begin(), String.end(), String1.begin(), ::toupper)

  • 인덱스배열을 사용하여 체크

0개의 댓글