백준 1157 단어공부 C++

Kkackit·2022년 1월 25일
0

Beakjoon

목록 보기
29/33

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

아스키 코드로 해결.

#include<iostream>
using namespace std;


int main(void)
{
    string input_String;
    
    cin>>input_String;

    int Alpha_Array[26];
    
    int most_often_Num = 0;

    bool isMost = true;
    for(int i = 0; i < 26; i++)
    {
        Alpha_Array[i] = 0;
    }

     
    for(int i = 0; i < input_String.size(); i++)
    {
        input_String[i] = tolower(input_String[i]);

        Alpha_Array[int(input_String[i]) - 97]++;
    }

    
    for(int i =1; i< 26; i++)
    {
        if(Alpha_Array[i] > Alpha_Array[most_often_Num])
        {
            most_often_Num = i;
            isMost= true;
        }
        else if(Alpha_Array[i] == Alpha_Array[most_often_Num])
        {
            isMost = false;
        }

    }

    if(isMost == false)
    {
        cout<<"?"<<endl;
    }
    else
    {
        cout<<char(most_often_Num + 65)<<endl;
    }


}

0개의 댓글