aboutsummaryrefslogtreecommitdiff
path: root/count_servers_communicate.c
diff options
context:
space:
mode:
Diffstat (limited to 'count_servers_communicate.c')
-rw-r--r--count_servers_communicate.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/count_servers_communicate.c b/count_servers_communicate.c
index 66d06be..c2f16eb 100644
--- a/count_servers_communicate.c
+++ b/count_servers_communicate.c
@@ -1,5 +1,6 @@
// 1267. Count Servers that Communicate
#include "leetcode.h"
+#include <stdio.h>
/*
* you are given a map of a server centre, represented as a 'm x n' integer
@@ -38,14 +39,19 @@ int main() {
int g1i[2][2] = {{1, 0}, {0, 1}};
int g2i[2][2] = {{1, 0}, {1, 1}};
int g3i[4][4] = {{1, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};
- struct two_d_arr g1, g2, g3;
- two_d_arr_init(&g1, ARRAY_SIZE(g1i), ARRAY_SIZE(g1i[0]), g1i);
- two_d_arr_init(&g2, ARRAY_SIZE(g2i), ARRAY_SIZE(g2i[0]), g2i);
- two_d_arr_init(&g3, ARRAY_SIZE(g3i), ARRAY_SIZE(g3i[0]), g3i);
- printf("%d\n", countServers(g1.arr, g1.row_size, g1.col_size)); // expect: 0
- printf("%d\n", countServers(g2.arr, g2.row_size, g2.col_size)); // expect: 3
- printf("%d\n", countServers(g3.arr, g3.row_size, g3.col_size)); // expect: 4
- two_d_arr_free(&g1);
- two_d_arr_free(&g2);
- two_d_arr_free(&g3);
+ struct two_d_arr *g1 =
+ two_d_arr_init(ARRAY_SIZE(g1i), ARRAY_SIZE(g1i[0]), g1i);
+ struct two_d_arr *g2 =
+ two_d_arr_init(ARRAY_SIZE(g2i), ARRAY_SIZE(g2i[0]), g2i);
+ struct two_d_arr *g3 =
+ two_d_arr_init(ARRAY_SIZE(g3i), ARRAY_SIZE(g3i[0]), g3i);
+ printf("%d\n", countServers(g1->arr, g1->row_size, g1->col_size)); // expect:
+ // 0
+ printf("%d\n", countServers(g2->arr, g2->row_size, g2->col_size)); // expect:
+ // 3
+ printf("%d\n", countServers(g3->arr, g3->row_size, g3->col_size)); // expect:
+ // 4
+ two_d_arr_free(g1);
+ two_d_arr_free(g2);
+ two_d_arr_free(g3);
}