-
Notifications
You must be signed in to change notification settings - Fork 110
/
rook_attack.cpp
46 lines (44 loc) · 1.37 KB
/
rook_attack.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
#include <vector>
#include "test_framework/generic_test.h"
#include <climits>
using std::vector;
void RookAttack(vector<vector<int>>* A_ptr) {
// TODO - you fill in here.
int rows = A_ptr->size();
int cols = (A_ptr->at(0)).size();
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if ((A_ptr->at(i))[j] == 0) {
for (int k = 0; k < cols; k++) {
if ((A_ptr->at(i))[k] != 0) {
A_ptr->at(i)[k] = INT_MIN;
}
}
for (int k = 0; k < rows; k++) {
if ((A_ptr->at(k))[j] != 0) {
A_ptr->at(k)[j] = INT_MIN;
}
}
}
}
}
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if ((A_ptr->at(i))[j] == INT_MIN) {
(A_ptr->at(i))[j] = 0;
}
}
}
return;
}
vector<vector<int>> RookAttackWrapper(vector<vector<int>> A) {
vector<vector<int>> a_copy = A;
RookAttack(&a_copy);
return a_copy;
}
int main(int argc, char* argv[]) {
std::vector<std::string> args{argv + 1, argv + argc};
std::vector<std::string> param_names{"A"};
return GenericTestMain(args, "rook_attack.cc", "rook_attack.tsv",
&RookAttackWrapper, DefaultComparator{}, param_names);
}