-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.cpp
60 lines (53 loc) · 1.57 KB
/
main.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
// Author : Qi Zhang
// Date : 2018-12-11
#include <bits/stdc++.h>
using namespace std;
vector<string> mysplit(string &s, char t){
vector<string> info;
string cur;
for(auto c: s){
if(c == t){
if(cur != "") info.push_back(cur);
cur = "";
}
else cur += c;
}
if(cur != "") info.push_back(cur);
return info;
}
bool check(vector<vector<string>>& board) {
vector<unordered_set<string>> row(9), column(9), box(9);
int m = board.size(), n = board[0].size();
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
string c = board[i][j];
if(c == "-") continue;
if(row[i].find(c) != row[i].end()) return false;
if(column[j].find(c) != column[j].end()) return false;
int pos = i/3 * 3 + j/3;
if(box[pos].find(c) != box[pos].end()) return false;
row[i].insert(c);
column[j].insert(c);
box[pos].insert(c);
}
}
return true;
}
int main()
{
string line;
while (getline(cin, line)) {
vector<string> tmp = mysplit(line, ' ');
vector<vector<string>> chess(9, vector<string>(9));
for(int b = 0; b < 9; b++){
vector<string> t = mysplit(tmp[b], ',');
int startx = b/3*3, starty = (b%3)*3, k = 0;
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
chess[startx+i][starty+j] = t[k++];
}
if(check(chess)) cout << "true" << endl;
else cout << "false" << endl;
}
return 0;
}