Short Cake
8PM - Animal Crossing Wild World

사생활 보호 설정

https://gamjia.tistory.com

Mini Rooms

  • 내 미니룸
  • 미니미설정
  • 미니룸설정
  • 답글수 [0]

What Friends Say

한마디로 표현해봐~

1촌평 관리

1157번 단어 공부

GamJia 2023. 3. 27. 09:13

단계별로 풀어보기 - 문자열 - 5단계

https://www.acmicpc.net/problem/1157

#include <iostream>
using namespace std;
int main()
{
    string S;
    cin >> S;

    int max = 0, count = 0, index;
    int arr[26] = { 0, };
    string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    for (int i = 0; i < S.length(); i++)
    {
        S.at(i) = toupper(S.at(i));
        arr[S.at(i) - 'A']++;    // 사용한 알파벳 개수 세기
    }

    for (int i = 0; i < 26; i++)
    {
        if (max < arr[i])
        {
            max = arr[i];
            count = 0;
            index = i;
        }

        if (max == arr[i])
        {
            count++;
        }
       
    }    

    if (count > 1)
    {
        cout << "?";
    }

    else
    {
        cout << (char)(index+'A');
    }

    return 0;
}

'BaekJoon' 카테고리의 다른 글

2908번 상수  (0) 2023.03.27
1152번 단어의 개수  (0) 2023.03.27
2675번 문자열 반복  (0) 2023.03.27
10809번 알파벳 찾기  (0) 2023.03.24
11720번 숫자의 합  (0) 2023.03.24