aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2020-05-30 20:59:02 +0000
committerrepl.it user2020-05-30 20:59:02 +0000
commit37bd33cce16c71cad3c50cb68e96a7ecb94d49cf (patch)
tree98cba132c9a38f34d4ac28c69fccff3c3a78a0a2
parent4efc505b1c8ec5a9fabca646fd54067aad15e91e (diff)
Latest version
-rw-r--r--.replit2
-rw-r--r--B.out5
-rw-r--r--C.out5
-rw-r--r--E.out5
-rw-r--r--G.out5
-rw-r--r--outputbin9485 -> 308 bytes
-rw-r--r--src/decode.cpp6
-rw-r--r--src/encode.cpp9
-rw-r--r--test7
9 files changed, 28 insertions, 16 deletions
diff --git a/.replit b/.replit
index a6206bd..62cae28 100644
--- a/.replit
+++ b/.replit
@@ -1,2 +1,2 @@
language = "cpp"
-run = "g++ src/*.cpp -o compress -std=c++1y; echo Compilation done; ./compress cowntact.txt 0"
+run = "g++ src/*.cpp -o compress -std=c++1y; echo Compilation done; ./compress cowntact.txt 85"
diff --git a/B.out b/B.out
new file mode 100644
index 0000000..54d66d9
--- /dev/null
+++ b/B.out
@@ -0,0 +1,5 @@
+cw-tpprs.wvng trees,dckng brnchs.looks bhnd.thy'r clsr.barn.bss veers,gllps cllr.sh'll safe.rchs door.blast,door lckd.pnckd.sddnly.spcfclly,strng lngth n.forth.one grnsy,one hlstn.ipt strng lngth n,1<=n<=100.opf ntgr
+Original length: 1245
+Compressed length: 186
+Percent compression: 85.0602%
+jvwn7F~?q\~wn[-x<gYVj5Mzw].y<x^WUUu:|>~?O'yw]WUUUu{^un[u:Nzo7s
diff --git a/C.out b/C.out
new file mode 100644
index 0000000..cfec2cb
--- /dev/null
+++ b/C.out
@@ -0,0 +1,5 @@
+vrybdy cloud cmptng days.tryng smpl one,sell mchns one two btchs clld slots.cstmr buy one scnd cpu q scnds ntgr q.ipt cnssts sngl line cntnng four ntgrs q,2<=q<=1000,ndd cmplt lngr btchs,m,1<=m<=1000000,mchns owned,s,0<=s<=1000000,1-scnd slots prchsd,l,0<=l<=1000000,q -scnd slots prchsd
+Original length: 1144
+Compressed length: 171
+Percent compression: 85.0524%
+z=y^}>y<|>gv]k5Mzo7yw{^Wunvn[-|_z^W}{om6yo{w;N}o[kZ-y
diff --git a/E.out b/E.out
new file mode 100644
index 0000000..88f18e9
--- /dev/null
+++ b/E.out
@@ -0,0 +1,5 @@
+ipt cntns two ntgrs n,1<=n<=200000,d,1<=d<=10^9,dvsr.ipt cntns n ntgrs _1,...,_n,0<=_<=10^9,a_i i th lmnt.opf dsply ntgr ndctng dstnct pairs ndcs (i,j) 1<=<j<=n _/d=_j/d ntgr dvsn c++.e._=_j ndcs i!=j
+Original length: 887
+Compressed length: 133
+Percent compression: 85.0056%
+j5y^}>y^Wzww]k5M&|{^z=yo[-y^k5FQunv~_u:p\k5
diff --git a/G.out b/G.out
new file mode 100644
index 0000000..d8cedd9
--- /dev/null
+++ b/G.out
@@ -0,0 +1,5 @@
+blgy lab ucf rcntly hvng prblms trnsmttng gntc sqncs cmptrs.nfrtntly,crrnt rprsnts gntc sqncs strng chrctrs,'a','c','g','t'.lckly,prfssr dvsd easy,gave task ctlly mplmntng.prblm,given gntc sqnc,opt crrspndng bs-10.lkws,given bs-10,opt crrspndng gntc sqnc.line ipt cntn pstv ntgr,q,rprsntng sqncs cnvrt.opf sqnc,opt hdr sqnc #j,j rprsnts sqnc prcssd,bgnnng 1.fllwng hdr,opt thr crrspndng gntc sqnc ntgr given,crrspndng bs-10 gntc sqnc
+Original length: 1592
+Compressed length: 238
+Percent compression: 85.0503%
+z=y^Wj5F}>Ot]Wz=Gt]~o[km6s\u:}>x^WUu].r{^z=aXu:o?yww]k5 APTUjv]Wu:cXkZV
diff --git a/output b/output
index c7606c9..c98c1a5 100644
--- a/output
+++ b/output
Binary files differ
diff --git a/src/decode.cpp b/src/decode.cpp
index 0d54dab..b812dae 100644
--- a/src/decode.cpp
+++ b/src/decode.cpp
@@ -2,14 +2,14 @@
#include "huffman.h"
/*int main() {
- ifstream enc("test");
+ ifstream enc("êõz=Çãñx¼Þïw»]®W«Õj5F£Ñèôz=žO'“Éär¹\\®×k5šÍf³Y¬V«Õj5†Ãa°X¬ÖkµZ­V«UªUªUªÕjµÚív»Ýî÷ûý~?");
stringstream ss;
ss << enc.rdbuf();
string s = ss.str();
vector<bool> v;
for (auto& c : s) {
- v.push_back(c == '1');
- //for (int i = 0; i < 8; ++i) v.push_back(1 & (c >> i));
+ //v.push_back(c == '1');
+ for (int i = 0; i < 8; ++i) v.push_back(1 & (c >> i));
}
cout << huffman::decode(v);
}*/ \ No newline at end of file
diff --git a/src/encode.cpp b/src/encode.cpp
index 69aafee..71ee6a2 100644
--- a/src/encode.cpp
+++ b/src/encode.cpp
@@ -356,17 +356,16 @@ string huffmancompress(string s)
{
vector<bool> enc = huffman::encode(s);
ofstream cout("output");
- for (auto b : enc) cout << b;
- cout << endl;
string ans;
- for (int i = 0; i < (int)enc.size(); ++i) {
+ for (int i = 0; i < (int)enc.size(); i += 8) {
char out = 0;
for (int j = i; j < min(i + 8, (int)enc.size()); ++j) {
if (enc[j]) out += (1 << (j - i));
}
ans += out;
}
- return ans;
+ cout << ans;
+ return ans;
}
int huffmancompresslength(string s)
@@ -458,8 +457,6 @@ int main(int argc, char *argv[]) {
cout << "Compressed length: " << s.size() << '\n';
cout << "Percent compression: " << 100.0 - ((double)100.0 * s.size() / orig_size) << "%\n";
cout << s << '\n';
- ofstream cout("test");
- cout << s << '\n';
// WARNING: Huffman will CRASH if you pass a string with only one unique character
/*string orig = "test1234";
diff --git a/test b/test
index c14a342..d2c0c1a 100644
--- a/test
+++ b/test
@@ -1,6 +1 @@
- APTUj5M&rn[-|>|o7fYVUu]z^k5Miv]kZz=gYu:?Otnv~w}{^u:cXkZVz^/e}>s\WUj5f{o7sw;~?qnvw]WUjZ}_}o[k5FQjmm[Vu:NSj5snv;sn}{^unm{wn[k5?Ot]Wj5Ftn7 x^k5 aXk5yw{ov]z=yo7Mzw].y^/y<Gz^/E}_/q_/ A Dh}>g3F#pn7 `X,E"d2F}_/K%dl6sn[VUU*r\WjZVUUUu]. A d2LS)Jt].K}_/ x<g3|>|>y^/E"HiZ-K% p8N'y^WUU*JR)x{}>O'IRT*q8N'I~o7M&bX,E"d2 ?G#A d2L&r\u:_/E"HRjZVU*
-B!bv].K%dv]kZ-K%Dhm6y<Oi4qn7?s\u]. A dYVU*Ez^/qn{=O' A HR)
-B!`X,E"d2F}_/K%dl6sn[VUU*Eh4Mi4MS)J% `Xk5M?aX,E"rn7x<Ot:s9g3 C!Hz=c1Li{^kZ-E"Dh}>G#bvw;s\k5fl{^/|>OiZVu].x<g3F#x<|>O'~o7Mt:NSjZV+
-`0F}_/E"HR)J~_/KRj5x<G}_/K%I$I$IR)
-x<q8g3~o[-r9~?s\u:GQu~?|_WjZ-E"Ht:s\W+b1LS)JR_/bX,E"H$dl6sn[-Kim[km[km6F~?q8Ni4~_kZ-b1Li4s9qn7F#Ht:pn7x^W+E"dl6sn[-{w;G#y<Ghmvn7|_Wun7x<O'd2fv;G#HRj5|>c1FhZkZVUU*J% {}>sn7F#Ht:G#r9NST*EQT*_Wu]. A d2fv;N}_/ APT*b1|_W+E"~o7Mt:cXVz=G#dl6s9q8g3FQun7?y<Gz^/bv]Wu].KR)
-aX,K%I$q8Nzomm{=O}>O'I$ A B}{=aX,E"HRu
+êõúý~¿ßï÷{=žÏçóy¼^¯×ë