본문 바로가기
SWEA

[SWEA] 1974. 스도쿠 검증

by 콩순이냉장고 2021. 8. 3.

문제 URL : https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV5Psz16AYEDFAUq&categoryId=AV5Psz16AYEDFAUq&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=2&pageSize=10&pageIndex=2 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

문제 접근법 : 가로,세로 3*3배열안에 123456789 가 있는지 일일이 확인하는것도 괜찮겠지만

그냥 가로의 행 인덱스가 1~9가 채워져있는짖 마찬가지로 세로가 1~9가채워져있는지

3*3의 하나의 군이라할때 거기도 1~9가 채워져있는지 확인하는겁니다. 하나씩 겹치는게 있다면 그것은 올바른

스도쿠가 아니고 겹치는게 없다면 올바른 수도쿠입니다.

 

소스코드 :

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//By 콩순이냉장고
#include <bits/stdc++.h>
using namespace std;
int n, k;
int row[10][10];
int column[10][10];
int gun[10][10];
int board[10][10];
void init() {
    memset(row, 0sizeof(row));
    memset(column, 0sizeof(column));
    memset(gun, 0sizeof(gun));
}
void input() {
    for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 9; j++) {
            cin >> board[i][j];
        }
    }
 
}
void solve() {
    for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 9; j++) {
            int num = board[i][j];
            int set = (i / 3* 3 + j / 3;
            if (row[i][num] || column[j][num] || gun[set][num]) {
                cout << 0 << "\n";
                return;
            }
            row[i][num] = column[j][num] = gun[set][num] = 1;
        }
    }
    cout << 1 << "\n";
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    int test;
    cin >> test;
    for (int i = 1; i <= test; i++) {
        init();
        input();
        cout << "#" << i << " ";
        solve();
        
    }
}
 
 
cs

 

궁금한점 혹은 모르는점 어떤 질문이든 댓글은 언제나 환영입니다.

 

'SWEA' 카테고리의 다른 글

[SWEA] 1979. 어디에 단어가 들어갈 수 있을까  (0) 2021.08.12
[SWEA] 11688. Calkin-Wilf tree 1  (0) 2021.08.11
[SWEA] 2001 파리 퇴치  (0) 2021.08.02
[SWEA] 2007 패턴 마디의 길이  (0) 2021.08.02
[SWEA] 10966 물놀이를 가자  (0) 2021.06.21