티스토리 뷰
import java.util.Scanner;
public class Main
{
public static int n=5;
public static int board[][]=new int[n][n];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int cnt=0;
for (int i=0;i<n;i++) { // initialize bingo board
for (int j=0;j<n;j++){
board[i][j]=sc.nextInt();
}
}
for (int i=0;i<n*n;i++) { // input and check
input_bb(sc.nextInt());
cnt=check_bingo();
//print_bb();
//System.out.println("debug :: " + cnt);
if (cnt>2) {
System.out.println(i+1);
break;
}
}
sc.close();
}
public static void input_bb(int a){
for (int i=0;i<n;i++) {
for (int j=0;j<n;j++) {
if (a==board[i][j]) {
board[i][j]=0;
}
}
}
}
public static void print_bb(){
for (int i=0;i<n;i++) {
for (int j=0;j<n;j++) {
System.out.format("%2d ",board[i][j]);
}
System.out.println();
}
}
public static int check_bingo() {
int rjudge[]=new int[n];
int cjudge[]=new int[n];
int djudge=0, rdjudge=0;
int judge=0;
for (int i=0;i<n;i++) {
for (int j=0;j<n;j++) {
//System.out.println("debug :: " + i + " " + j);
rjudge[i]+=board[i][j];
cjudge[j]+=board[i][j];
if (i==j) djudge+=board[i][j];
if (i+j==4) rdjudge+=board[i][j];
}
}
for (int i=0;i<n;i++) {
if (rjudge[i]==0) judge++;
if (cjudge[i]==0) judge++;
}
if (djudge==0) judge++;
if (rdjudge==0) judge++;
return judge;
}
}
'알고리즘' 카테고리의 다른 글
1143: 소시지 공장 (0) | 2015.04.09 |
---|---|
1124: 두 수의 최소합(알고리즘) (0) | 2015.04.07 |
1112: 빙고(알고리즘) (0) | 2015.04.06 |
1111: 우정수와 완전수 (0) | 2015.04.06 |
1110: 피타고라스 수 (0) | 2015.04.06 |
- Total
- Today
- Yesterday
- 1143
- 소수
- 1110
- 시험후기
- 1045
- java
- 1044
- ASCII
- 1048
- 1124
- Git
- 팀을위한GIT
- 1002
- 최소공배수
- 소인수분해
- 등차수열
- 1111
- 1050
- 근의공식
- 1112
- 1046
- CH340G
- 챗봇
- OS설치
- 1104
- acmicpc
- 반올림
- 1103
- 센서
- 최대공약수
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |