[C#] 백준 1157번 단어 공부
2021. 12. 19. 00:48ㆍC#/[백준] 문자열
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만 있으면 되기 때문에 중복제거를 해준다.
'C# > [백준] 문자열' 카테고리의 다른 글
[C#] 백준 1152번 단어의 개수 (0) | 2021.12.19 |
---|---|
[C#] 백준 2675번 문자열 반복 (0) | 2021.12.19 |
[C#] 백준 10809번 알파벳 찾기 (0) | 2021.12.19 |
[C#] 백준 11720번 숫자의 합 (0) | 2021.12.19 |
[C#] 백준 11654번 아스키 코드 (0) | 2021.12.19 |