백준 2082

hong030·2023년 3월 6일
0
  • 실버 3단계 문제

풀이)

  1. 디지털 숫자가 저장된 2차원 배열을 만든다.
  2. char형 2차원 배열에 입력 받는다.
  3. 입력받은 숫자 4개에 대해 0~9까지 서로 비교한다. 이 때 내 시계엔 불이 켜져있는데 digit에 불이 안 켜져있으면 이 숫자는 아니므로 break로 넘어간다.

주의할 점)

모든 digit를 배열에 넣고 비교하면 시간이 초과될까봐 푸는 방법을 찾기 어려워했다. 비록 시간초과가 나더라도 겁먹지 말고 일단 풀어보는 습관을 들이자.

내 코드)

import java.io.*;
import java.util.*;

public class Backjoon2082 {
	public static void main(String[] args) throws IOException {
		
		//digit 저장.
		char []zero =  "####.##.##.####".toCharArray();
		char []one =   "..#..#..#..#..#".toCharArray();
		char []two =   "###..#####..###".toCharArray();
		char []three = "###..####..####".toCharArray();
		char []four =  "#.##.####..#..#".toCharArray();
		char []five =  "####..###..####".toCharArray();
		char []six =   "####..####.####".toCharArray();
		char []seven = "###..#..#..#..#".toCharArray();
		char []eight = "####.#####.####".toCharArray();
		char []nine =  "####.####..####".toCharArray();
		
		char [][]digit = new char[][]{
				zero, one, two, three, four, five, six, seven, eight, nine
		};
		
		//입력받기.
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		String input[] = new String[] {"", "", "", ""};
		
		for(int i=0;i<5;i++) {
			StringTokenizer st = new StringTokenizer(bf.readLine());
			String temp1= st.nextToken();
			String temp2= st.nextToken();
			String temp3= st.nextToken();
			String temp4= st.nextToken();
			input[0] += temp1;
			input[1] += temp2;
			input[2] += temp3;
			input[3] += temp4;			
		}

		char [][] myClock = new char[4][15];
		for(int i=0;i<4;i++) {
			myClock[i] = input[i].toCharArray();
		}
		
		
		int i, j, k;
		for(i=0;i<4;i++) {
			for(j=0;j<10;j++) {
				for(k=0;k<15;k++) {
					if (myClock[i][k]=='#' && digit[j][k]=='.') break;				
				}
				
				if(k==15) {
					System.out.print(j);
					break;}
			}
			if(i==1) System.out.print(":");
		}

	}
}

profile
자바 주력, 프론트 공부 중인 초보 개발자. / https://github.com/hongjaewonP

0개의 댓글