본문 바로가기
알고리즘/백준 BOJ

[ BOJ/C# ] 1157 단어 공부

by 왹져박사 2023. 8. 20.
728x90

문자와 아스키코드를 이용하여 해결하였다. 아스키코드의 변환을 이용하는 것은 항상 재밌다!

using System;

namespace _1157
{
    class Program
    {
        static void Main()
        {
            string str = Console.ReadLine();
            int[] n = new int[26];

            if (str != null)
            {
                str = str.ToUpper();
                //Console.WriteLine(str);
                char[] alphabets = str.ToCharArray();

                for(int i = 0; i < alphabets.Length; i++)
                {
                    //Console.WriteLine("i : {0}, alphabet : {1}", i, alphabets[i] - 65);
                    n[alphabets[i] - 65]++;
                }

                int max = n.Max();
                int m = 0;
                for (int i = 0; i < n.Length; i++)
                {
                    if (n[i] == max) m++;
                }
                if (m != 1) Console.WriteLine("?");
                else Console.WriteLine(Convert.ToChar(Array.IndexOf(n, max) + 65));
            }
        }
    }
}

728x90

'알고리즘 > 백준 BOJ' 카테고리의 다른 글

[ BOJ/C# ] 3052 나머지  (0) 2023.08.21
[ BOJ/C# ] 2562 최댓값  (0) 2023.08.21
[ BOJ/C# ] 1550 16진수  (0) 2023.08.20
[ BOJ/C# ] 1330 두 수 비교하기  (0) 2023.08.20
[ BOJ/C++ ] 10699 오늘 날짜  (0) 2023.08.20