백준 #30958번 서울사이버대학을 다니고

jhj·2024년 5월 20일

백준 JAVA

목록 보기
483/583
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		sc.nextLine();
		String a = sc.nextLine();
		
		int[] alpha = new int[26];
		int[] count = new int[26];
		
		for(int i = 0; i < alpha.length; i++) {
			alpha[i] = 97 + i;
			count[i] = 0;
		}
		
		for(int i = 0; i < a.length(); i++) {
			for(int j = 0; j < alpha.length; j++) {
				if(a.charAt(i) == alpha[j]) {
					count[j]++;
				}
			}
		}
		
		int max = count[0];
		for(int i = 0; i < count.length; i++) {
			max = Math.max(max, count[i]);
		}
		System.out.println(max);
		
		sc.close();
	}
}

정수 입력 받고, nextLine()을 활용하여 입력을 받아야 할 경우, nextLine()을 입력 받기 전에 한번 더 써서 버퍼를 비워주어야 한다.

profile
개발자를 꿈꾸는

0개의 댓글