#include "grader.h"
#include "encoder.h"
int const N = 1e3 + 9;
int const H = 40;
int d[H][N];
bool odw[H][N];
int G[N][N];
int R[N];
void dfs(int v, int in, int w) {
odw[in][v] = true;
d[in][v] = w;
for (int i = 0; i < R[v]; i++) {
int sas = G[v][i];
if (!odw[in][sas])
dfs(sas, in, w + 1);
}
}
void int_to_bits(int a) { //9 bitów
int pot = 1 << 9;
while (a > 0) {
if (a > pot) {
encode_bit(1);
a -= pot;
}
else encode_bit(0);
pot >>= 1;
}
}
void encode(int nv, int nh, int ne, int* v1, int* v2) {
for (int i = 0; i < ne; i++) {
G[v1[i]][R[v1[i]] = G[v2[i]];
R[v1[i]]++;
G[v2[i]][R[v2[i]] = G[v1[i]];
R[v2[i]]++;
}
for (int h = 0; h < nh; h++) {
dfs(h, h, 0);
for (int v = 0; v < nv; v++) {
int_to_bits(d[h][v]);
}
}
return;
}
#include "grader.h"
#include "decoder.h"
void decode(int nv, int nh) {
for (int h = 0; h < nh; h++) {
for (int v = 0; v < nv; v++) {
int mn = 1;
int a = 0;
for (int i = 0; i < 9; i++) {
int bit = decode_bit();
a += bit * mn;
mn <<= 2;
}
hops(h, v, a);
}
}
}
Compilation message
encoder.cpp: In function 'void encode(int, int, int, int*, int*)':
encoder.cpp:36:36: error: invalid conversion from 'int*' to 'int' [-fpermissive]
36 | G[v1[i]][R[v1[i]] = G[v2[i]];
| ~~~~~~~^
| |
| int*
encoder.cpp:36:37: error: expected ']' before ';' token
36 | G[v1[i]][R[v1[i]] = G[v2[i]];
| ^
| ]
encoder.cpp:38:36: error: invalid conversion from 'int*' to 'int' [-fpermissive]
38 | G[v2[i]][R[v2[i]] = G[v1[i]];
| ~~~~~~~^
| |
| int*
encoder.cpp:38:37: error: expected ']' before ';' token
38 | G[v2[i]][R[v2[i]] = G[v1[i]];
| ^
| ]