개발자 톡
연습문제 톡
[21년 재직자 대회 예선] 전광판
자바 문자열로
- 등록일
- 2025-01-29 18:40:44
- 조회수
- 14
- 작성자
- zanghwkddnwl
import java.io.*; import java.util.*; public class Main { static int[][] numState = { {1,1,0,1,1,1,1}, {0,1,0,1,0,0,0}, {1,1,1,0,1,1,0}, {1,1,1,1,1,0,0}, {0,1,1,1,0,0,1}, {1,0,1,1,1,0,1}, {1,0,1,1,1,1,1}, {1,1,0,1,0,0,1}, {1,1,1,1,1,1,1}, {1,1,1,1,1,0,1} }; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int phase = Integer.parseInt(br.readLine()); for(int i = 0; i < phase; i++){ String[] target = br.readLine().split(" "); String a = String.format("%5s",target[0]).replace(" ","O"); String b = String.format("%5s",target[1]).replace(" ","O"); int[] aArr = new int[5]; int[] bArr = new int[5]; for(int j = 0; j < 5; j++){ aArr[j] = a.charAt(j)!='O'?(int)a.charAt(j)-'0':-1; } for(int j = 0; j < 5; j++){ bArr[j] = b.charAt(j)!='O'?(int)b.charAt(j)-'0':-1; } int sum = 0; for(int j = 0; j < 5; j++){ int aNum = aArr[j]; int bNum = bArr[j]; if(aNum != -1 || bNum != -1){ if(aNum == -1 && bNum != -1){ int oneCount = (int)Arrays.stream(numState[bNum]).filter(item -> item == 1).count(); sum += oneCount; }else if(aNum != -1 && bNum == -1){ int oneCount = (int)Arrays.stream(numState[aNum]).filter(item -> item == 1).count(); sum += oneCount; }else{ int cnt = 0; for(int k = 0; k < 7; k++){ if(numState[aNum][k] != numState[bNum][k]) cnt++; } sum += cnt; } } } bw.write(sum+"\n"); } bw.flush(); bw.close(); } }
#[21년_재직자_대회_예선]_전광판