백준온라인

[백준온라인] 13772번 Holes

cbkpar 2021. 8. 9. 00:00

문제 : https://www.acmicpc.net/problem/13772

 

13772번: Holes

Input starts with an integer, N, on a line of its own (0 < N <= 30). It tells you how many lines of text follow. There then follow N lines of text. Each line contains a string of text composed only of upper case letters and spaces; it will contain at least

www.acmicpc.net

 

문제 요약 : 해당 문자열 알파벳에 있는 구멍의 총 개수 출력

입력 출력
1 ≤ N(문자열 개수) ≤ 30
1 ≤ L(문자길이) ≤ 250
해당 문자열 알파벳에 있는 구멍의 총 개수 출력

 

JAVA

소스코드 : https://github.com/cbkpar/BOJ/blob/main/boj_13772.java

채점 번호 아이디 문제 번호 결과 메모리 시간 언어 코드 길이
31655790 cbkpar 13772 맞았습니다!! 14304KB 140ms Java 11 648B
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int[] arr = {1,2,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0};
		int n,i,sz,s;
		n = Integer.parseInt(br.readLine());
		while(n-->0) {
			String str = br.readLine();
			sz = str.length();
			s = 0;
			for(i=0;i<sz;i++) if(str.charAt(i)>='A'&&str.charAt(i)<='Z') s += arr[str.charAt(i)-'A'];
			sb.append(s+"\n");
		}
		System.out.println(sb);
	}
}

A, D, O, P, Q, R의 경우 1개

B 의 경우 2개

그 외 0 개

로 전처리 후 계산해준다.