update
This commit is contained in:
parent
04ae85a14d
commit
cf623bac83
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
out
|
|
@ -29,17 +29,19 @@ namespace huffman {
|
|||
v.push_back(1);
|
||||
for (int i = 0; i < 8; ++i) v.push_back(1 & (n->c >> i));
|
||||
}
|
||||
else v.push_back(0);
|
||||
if (n->l) {
|
||||
v.push_back(1);
|
||||
encode_tree(n->l, v);
|
||||
else {
|
||||
v.push_back(0);
|
||||
if (n->l) {
|
||||
v.push_back(1);
|
||||
encode_tree(n->l, v);
|
||||
}
|
||||
else v.push_back(0);
|
||||
if (n->r) {
|
||||
v.push_back(1);
|
||||
encode_tree(n->r, v);
|
||||
}
|
||||
else v.push_back(0);
|
||||
}
|
||||
else v.push_back(0);
|
||||
if (n->r) {
|
||||
v.push_back(1);
|
||||
encode_tree(n->r, v);
|
||||
}
|
||||
else v.push_back(0);
|
||||
}
|
||||
|
||||
int idx = 0;
|
||||
|
@ -47,14 +49,16 @@ namespace huffman {
|
|||
if (v[idx++] == 1) {
|
||||
for (int i = 0; i < 8; ++i) n->c |= (1 << v[idx++]);
|
||||
}
|
||||
if (v[idx++] == 1) {
|
||||
n->l = new node(0, 0);
|
||||
decode_tree(n->l, v);
|
||||
}
|
||||
if (v[idx++] == 1) {
|
||||
n->r = new node(0, 0);
|
||||
decode_tree(n->r, v);
|
||||
}
|
||||
else {
|
||||
if (v[idx++] == 1) {
|
||||
n->l = new node(0, 0);
|
||||
decode_tree(n->l, v);
|
||||
}
|
||||
if (v[idx++] == 1) {
|
||||
n->r = new node(0, 0);
|
||||
decode_tree(n->r, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void generate(vector<int> f) {
|
||||
|
@ -76,7 +80,7 @@ namespace huffman {
|
|||
void solve(node * n, vector<bool> & v, string & s) {
|
||||
if (n->c) {
|
||||
s += n->c;
|
||||
cout << (int)n->c << '\n';
|
||||
//cout << (int)n->c << '\n';
|
||||
if (idx > v.size()) return;
|
||||
solve(root, v, s);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ int getweight(string s)
|
|||
{
|
||||
if(s[0]=='$')
|
||||
return 1000;
|
||||
else if(s=="Farmer"||s=="a"||s=="example")return 1;
|
||||
else if(s=="farmer"||s.length()==1||s=="example")return 1;
|
||||
else return 10;
|
||||
}
|
||||
struct clause
|
||||
|
@ -24,7 +24,8 @@ struct clause
|
|||
for(int j=0;j<s.length();j++)
|
||||
{
|
||||
if(s.at(j)=='$') iseq=!iseq;
|
||||
if(('a'<=s.at(j)&&s.at(j)<='z')||('A'<=s.at(j)&&s.at(j)<='Z')||('0'<=s.at(j)&&s.at(j)<='9')||(iseq&&s.at(j)=='$')))word+=s.at(j);
|
||||
if(('a'<=s.at(j)&&s.at(j)<='z')||('A'<=s.at(j)&&s.at(j)<='Z')||('0'<=s.at(j)&&s.at(j)<='9')||(iseq&&s.at(j)!=' '))
|
||||
word+=('A'<=s.at(j)&&s.at(j)<='Z')?(s.at(j)-'A'+'a'):(s.at(j));
|
||||
else
|
||||
{
|
||||
if(!iseq)
|
||||
|
|
Loading…
Reference in a new issue