-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
44 lines (31 loc) · 861 Bytes
/
main.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
#include <functional>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include "hamming.hpp"
using namespace std;
const auto usage = "./hamming [encode|decode]"s;
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
if (argc != 2) {
cout << usage << endl;
return EXIT_FAILURE;
}
function<vector<uint8_t>(const vector<uint8_t> &)> op;
if (argv[1] == "encode"s) { op = encode; }
else if (argv[1] == "decode"s) { op = decode; }
else {
cout << usage << endl;
return EXIT_FAILURE;
}
cin >> noskipws;
istream_iterator<uint8_t> begin(cin), end;
vector<uint8_t> bytes(begin, end);
auto result = op(bytes);
copy(result.begin(),
result.end(),
ostream_iterator<uint8_t>(cout)
);
return EXIT_SUCCESS;
}