2022/JAVA

ep 05-2. 문제 풀이

L_SU 2022. 12. 2. 03:52

1157번: 단어 공부 (acmicpc.net)

 

1157번: 단어 공부

알파벳 대소문자로 된 단어가 주어지면, 이 단어에서 가장 많이 사용된 알파벳이 무엇인지 알아내는 프로그램을 작성하시오. 단, 대문자와 소문자를 구분하지 않는다.

www.acmicpc.net

import java.util.Scanner;

public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next().toUpperCase();
		int[]count = new int[26];
		
		for(int i=0; i<str.length(); i++){
		    int num = str.charAt(i) - 'A';
		    count[num]++;
		}
		int max = 0;
		char result = '?';
		
		for(int i=0; i<count.length; i++){
		    if(max < count[i]){
		        max = count[i];
		        result = (char)(i+'A');
		    } else if (max==count[i]){
		        result = '?';
		    }
		}
		System.out.println(result);
	}
}

 

11654번: 아스키 코드 (acmicpc.net)

 

11654번: 아스키 코드

알파벳 소문자, 대문자, 숫자 0-9중 하나가 주어졌을 때, 주어진 글자의 아스키 코드값을 출력하는 프로그램을 작성하시오.

www.acmicpc.net

import java.util.Scanner;

public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char ch = sc.next().charAt(0);
		int n = (int)ch;
		System.out.println(n);
	}
}