๐ฉ๐ปProgramming/Coding Test
[C#] [BOJ#1157] ๋จ์ด ๊ณต๋ถ
taesooya
2022. 7. 30. 23:42
https://www.acmicpc.net/problem/1157
1157๋ฒ: ๋จ์ด ๊ณต๋ถ
์ํ๋ฒณ ๋์๋ฌธ์๋ก ๋ ๋จ์ด๊ฐ ์ฃผ์ด์ง๋ฉด, ์ด ๋จ์ด์์ ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉ๋ ์ํ๋ฒณ์ด ๋ฌด์์ธ์ง ์์๋ด๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. ๋จ, ๋๋ฌธ์์ ์๋ฌธ์๋ฅผ ๊ตฌ๋ถํ์ง ์๋๋ค.
www.acmicpc.net
My Solution
- ํน์ ๋ฌธ์ ๊ฐ์ ์ฐพ๊ธฐ (๋๋ค์) _ ๋ฐ์ค 1
- Linq๋ฅผ ์ด์ฉํ ์ต๋๊ฐ๊ณผ ์ต๋๊ฐ์ ์ธ๋ฑ์ค ์ฐพ๊ธฐ_๋ฐ์ค 2
using System;
using System.Linq;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine().ToUpper();
string alphab = "ABCDEFGHIJKLMNOPQRSTUVWZYX";
char[] alphabets = alphab.ToCharArray();
int[] count = new int[26];
for (int i = 0; i < 26; i++)
{
count[i] = s.Count(f => f == alphabets[i]);
}
int max = count.Max();
int position = Array.IndexOf(count, max);
Array.Sort(count);
Array.Reverse(count);
if (count[0] == count[1])
{
Console.WriteLine("?");
}
else Console.WriteLine(alphabets[position]);
}
}
}