diff options
author | Anthony Wang | 2020-05-30 03:22:03 +0000 |
---|---|---|
committer | repl.it user | 2020-05-30 03:22:03 +0000 |
commit | fbd1d1905864ec04dad55ff7d8ec9cef75a918ff (patch) | |
tree | b12f9cdf76bdd527419f836bbb04ca7eafd188b1 | |
parent | 115f31e0af39bfb18c7bf36700565942dd41d742 (diff) |
Fixed some bugs
-rw-r--r-- | .replit | 2 | ||||
-rw-r--r-- | src/main.cpp | 6 |
2 files changed, 5 insertions, 3 deletions
@@ -1,2 +1,2 @@ language = "cpp"
-run = "g++ src/*.cpp -o compress -std=c++1y; echo \"Compilation done\n\"; ./compress" +run = "g++ src/*.cpp -o compress -std=c++1y; echo Compilation done; ./compress" diff --git a/src/main.cpp b/src/main.cpp index 0bfdda1..e22b414 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -301,10 +301,11 @@ string huffmancompress(string s) for (int i = 0; i < ((int)enc.size() + 7) / 8; ++i) { char out = 0; for (int j = i; j < min(i + 8, (int)enc.size()); ++j) { - if (enc[j]) i += (1 << (j - i)); + if (enc[j]) out += (1 << (j - i)); } ans += out; } + return ans; } int initsize=0; @@ -366,7 +367,8 @@ int main() { output.preprocess(-1); string s = output.gettextstring(-100000); for (auto& c : s) if (c == '\r') c = ' '; - //printf("%s\n", s.c_str()); + s = huffmancompress(s); + printf("%s\n", s.c_str()); |