프로그래밍언어/알고리즘
백준 1157 단어 공부_JAVA
새끼개발자
2023. 7. 14. 17:44
https://www.acmicpc.net/problem/1157
1157번: 단어 공부
알파벳 대소문자로 된 단어가 주어지면, 이 단어에서 가장 많이 사용된 알파벳이 무엇인지 알아내는 프로그램을 작성하시오. 단, 대문자와 소문자를 구분하지 않는다.
www.acmicpc.net
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int arr[] = new int[26];
String s = sc.next();
for (int i = 0 ; i < s.length() ; i++){
//대문자와 소문자 계산
if (s.charAt(i) > 64 && s.charAt(i) < 97){
arr[s.charAt(i)-65] ++;
}else{
arr[s.charAt(i)-97] ++;
}
}
int max = 0 ;
char ch = '?';
for (int i = 0 ; i max){
max = arr[i];
ch = (char) (i + 65); //대문자
}else if(max == arr[i]){
ch = '?';
}
}
System.out.println(ch);
sc.close();
}
}