-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunzip.cpp
More file actions
49 lines (44 loc) · 1.06 KB
/
unzip.cpp
File metadata and controls
49 lines (44 loc) · 1.06 KB
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
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ln '\n'
using namespace std;
ifstream fin("file.myzip", ios::binary);
ofstream fout("new.txt");
uint8_t len, x, y;
char b, tmp;
string s;
int nr;
unordered_map<string, char> mp;
int main(){
fin.get(tmp);
len = static_cast<uint8_t>(tmp);
for(int i = 0; i < len; i++){
fin.get(b);
fin.get(tmp);
x = static_cast<uint8_t>(tmp);
int copie = x;
while(copie > 0){
fin.get(tmp);
y = static_cast<uint8_t>(tmp);
nr = max(8 - copie, 0);
for(int j = 7; j >= nr; j--)
s += (((y >> j) & 1) == 0 ? '0' : '1');
copie -= 8;
}
mp[s] = b;
s = "";
}
s = "";
while(fin.get(b)){
x = static_cast<uint8_t>(b);
for(int i = 7; i >= 0; i--){
s += (((x >> i) & 1) == 0 ? '0' : '1');
auto it = mp.find(s);
if(it != mp.end()){
fout<<it->second;
s = "";
}
}
}
}