[C#] 백준 1157번 단어 공부

2021. 12. 19. 00:48C#/[백준] 문자열

using System;
using System.Collections.Generic;
using System.Linq;

namespace _5
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string upper = input.ToUpper();
            List<string> inputList = new();
            List<char> checkWord = upper.Distinct().ToList();
            int number = 0;
            char output = ' ';
            bool equalCheck = false;
            int count;
            if (input.Length > 1) 
            {
                for (int i = 0; i < checkWord.Count; i++)
                {
                    count = 0;
                    for (int j = 0; j < upper.Length; j++)
                    {
                        if (checkWord[i] == upper[j])
                        {
                            count++;
                        }

                    }
                    if (number < count)
                    {
                        number = count;
                        output = checkWord[i];
                        equalCheck = false;
                    }
                    else if (number == count)
                        equalCheck = true;
                    else if (number > count)
                        continue;
                }
            }
            else
                output = Convert.ToChar(upper);

            if (equalCheck == true)
                Console.WriteLine("?");
            else if(equalCheck == false)
                Console.WriteLine(output);
        }
    }
}

어차피 대문자로 출력할거고 대소문자를 구별하지 않기 때문에 모두 Toupper를 통해 대문자로 만들어준다.

mississipi 에서 misp만 있으면 되기 때문에 중복제거를 해준다.