본문 바로가기
카테고리 없음

백준 #1157 2023-07-25

by 하타라시 2023. 7. 26.

코드를 짧게 한답시고 해봤는데 소요시간이 246ms인가 나와서 슬펐습니당,,,,,

string put = Console.ReadLine();  //입력
Dictionary<char,int> putDictionary = new Dictionary<char,int>(); //딕셔너리에 한 번 이상 나온 데이터만 추가

for(int i = 0; i < put.Length; i++){
    char toUpper = char.Parse(put[i].ToString().ToUpper());
    if(!putDictionary.ContainsKey(toUpper)){ //한 번 이상 나왔을경우 추가
        putDictionary.Add(toUpper,0);
    }
    putDictionary[toUpper]++; //카운트 1 증가
}
    int max = putDictionary.Values.Max(); //최대값 저장
    var test = putDictionary.Keys.Where(n => putDictionary[n] == max); //최대값의 문자 저장
    if (putDictionary.Values.Count(n => n == max) > 1) //1 초과할경우 2개이상으로 간주
        Console.Write("?");
    else
        Console.Write(string.Concat(test)); //char에서 string으로 ,,, new string(test); 이거도 될려나..