-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.cpp
More file actions
50 lines (37 loc) · 806 Bytes
/
demo.cpp
File metadata and controls
50 lines (37 loc) · 806 Bytes
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
#include "bwTransform.h"
#include <cstdio>
using namespace std;
int main(int argc, char* argv[]) {
bool verbose = (argc > 1 && string(argv[1]) == VERBOSE_FLAG);
int n;
scanf("%d\n", &n);
char* in = new char[n + 2];
in[0] = START_SYMBOL;
fgets(in + 1, n + 1, stdin);
in[n+1] = END_SYMBOL;
if (verbose) {
printf("Input:\n%.*s\n\n", n, in + 1);
}
char* out = bwEncode(in, n + 2);
if (verbose) {
printf("Encoded:\n%.*s\n\n", n + 2, out);
}
char* dec = bwDecode(out, n + 2);
if (verbose) {
printf("Decoded:\n%.*s\n\n", n, dec + 1);
}
bool ok = true;
for (int i = 0; i < n + 2; i++) if (in[i] != dec[i]) {
ok = false;
break;
}
if (ok) {
printf("OK\n");
} else {
printf("DECODED STRING INVALID\n");
}
delete[] in;
delete[] out;
delete[] dec;
return 0;
}