구현 - BOJ 1157 단어 공부

LEE ·2023년 7월 28일
0

알고리즘 기출문제

목록 보기
57/60

구현코드

import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		int[] count = new int[91];
		
		int length = str.length();
		for(int i = 0 ; i < length; i ++){
			
			int k = (int)str.charAt(i);
			k = k >= 97 ? (k - 32)  : k;
			count[k] += 1;
			
		}
		int max = 0;
		int index = 0;
		
		for(int i = 65 ; i <=90; i ++){
			if(max < count[i]){
				max = count[i];
				index = i;
			}
		}
		
		Arrays.sort(count);
		if(count[89] == count[90]){
			System.out.println("?");
		}else{
			System.out.println((char)(index));
		}
		
		
	}
}

코드해석

대 소문자에 모두 카운트를 해줘야 하는 문제이다.
또한 최대 값의 index 값을 구해야 하는문제.

0개의 댓글

관련 채용 정보