-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathsudoku.cpp
64 lines (48 loc) · 1.1 KB
/
sudoku.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
// SPOJ Problem Set (seletivas) - SUDOIME
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string correct_sudoku(vector< vector<int> > matrix) {
vector<int> vetorzin_1;
vector<int> vetorzin_2;
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
vetorzin_1.push_back(matrix[i][j]);
vetorzin_2.push_back(matrix[j][i]);
}
sort(vetorzin_1.begin(), vetorzin_1.end());
sort(vetorzin_2.begin(), vetorzin_2.end());
for (int j = 0; j < 9; j++) {
if ((vetorzin_1[j] != j+1) || (vetorzin_2[j] != j+1))
return "NAO";
}
vetorzin_1.clear();
vetorzin_2.clear();
}
}
int main() {
int n, counter=1, temp;
string result="SIM";
vector<int> vetor;
vector< vector<int> > matrix;
cin >> n;
while(n--) {
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
cin >> temp;
vetor.push_back(temp);
}
matrix.push_back(vetor);
vetor.clear();
}
result = correct_sudoku(matrix);
cout << "Instancia " << counter << endl;
cout << result << endl;
result="SIM";
matrix.clear();
counter++;
}
return 0;
}