-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidSudoku_36.cpp
67 lines (62 loc) · 1.82 KB
/
ValidSudoku_36.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// ValidSudoku_36.cpp
// LeetcodeByEcho
//
// Created by echo on 2019/4/15.
// Copyright © 2019 DE. All rights reserved.
//
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <math.h>
using namespace std;
bool isValidSudoku(vector<vector<char>>& board) {
for(int k = 0; k < 3; ++k){
for(int i = 0; i < 9; i++){
int a[9] = {0};
for(int j= 0; j < 9; j ++){
char ele;
if (k == 0){
ele = board[i][j];
}else if(k == 1) {
ele = board[j][i];
}else{
int i_ = i/3*3+j/3;
int j_ = i%3*3+j%3;
std::cout<<"("<<i<<","<<j<<"), (" << i_ << "," << j_<<")"<<std::endl;
ele = board[i_][j_];
}
if(ele != '.'){
int x = ele - '0'-1;
a[x] += 1;
if (a[x] != 1){
return false;
}
}
}
}
}
return true;
}
int main(int argc, const char * argv[]) {
int a[9][9] = {{'8','3','.','.','7','.','.','.','.'},
{'6','.','.','1','9','5','.','.','.'},
{'.','9','8','.','.','.','.','6','.'},
{'8','.','.','.','6','.','.','.','3'},
{'4','.','.','8','.','3','.','.','1'},
{'7','.','.','.','2','.','.','.','6'},
{'.','6','.','.','.','.','2','8','.'},
{'.','.','.','4','1','9','.','.','5'},
{'.','.','.','.','8','.','.','7','9'}};
vector< vector<char> > A ;
for(int i = 0; i < 9; ++i){
vector<char> aa;
for(int j = 0; j < 9; j++){
aa.push_back(a[i][j]);
}
A.push_back(aa);
}
std::cout<<A.size();
std::cout<<isValidSudoku(A);
}