Update main.cpp

This commit is contained in:
Anthony Wang 2020-05-26 18:25:37 +00:00 committed by repl.it user
parent 63cbc35ea6
commit dc1a7d52b8

View file

@ -49,7 +49,8 @@ struct clause
if(word!="") words.pb(word);
}
void calcweight()
{
{
weights.clear();
for(auto& w: words)weights.pb(getweight(w));
for(auto& w: weights) weight=weight+w;
}
@ -67,6 +68,7 @@ struct clause
}
else ans+=" "+words[i];
}
return ans;
}
};
struct sentence
@ -115,19 +117,19 @@ struct sentence
bool iss=true;
string ans="";
for(auto& c:clauses)
if(c.weight.clause>=minw)
if(c.weight.clause>=minw)
{
string tmp=c.gettext(minw);
if(tmp.length()>0)
{
string tmp=c.gettext();
if(tmp.length()>0)
if(iss)
{
if(iss)
{
iss=false;
ans+=c.gettext();
}
else ans+=" "+words[i];
iss=false;
ans=ans+tmp;
}
else ans+=","+tmp;
}
}
return ans;
}
@ -159,25 +161,44 @@ void init()
sentencefile+=' ';
}
for(auto& i:text)i.parse();
}
}
string gettextstring(int minw)
{
bool iss=true;
string ans="";
for(auto& c:text)
if(c.weight.sentence>=minw)
{
string tmp=c.gettext(minw);
if(tmp.length()>0)
{
if(iss)
{
iss=false;
ans=ans+tmp;
}
else ans+="."+tmp;
}
}
return ans;
}
int main() {
init();
for(sentence& i:text)
{
for(clause& j:i.clauses)
{
for(auto k:j.words)
{
cout<<k<<endl;
}
}
}
/*string orig = "Snow has arrived on the farm, and as she does at the beginning of every winter, Bessie is building a snow-cow! Most of the time, Bessie strives to make her sculpture look as much like a real cow as possible. However, feeling artistically inspired, this year she decides to pursue a more abstract route and build a sculpture in the shape of a tree, consisting of N snowballs (1<=N<=105) connected by N-1 branches, each connecting a pair of snowballs such that there is a unique path between every pair of snowballs. Bessie has added a nose to one of the snowballs, so it represents the head of the abstract snow cow. She designates it as snowball number 1. To add more visual interest, she plans to dye some of the snowballs different colors in an artistic fashion by filling old milk pails with colored dye and splashing them onto the sculpture. Colors are identified by integers in the range 1...105, and Bessie has an unlimited supply of buckets filled with dyes of every possible color. When Bessie splashes a snowball with a bucket of dye, all the snowballs in its subtree are also splashed with the same dye (snowball y is in the subtree of snowball x if x lies on the path from y to the head snowball). By splashing each color with great care, Bessie makes sure that all colors a snowball has been splashed with will remain visible. For example, if a snowball had colors [1,2,3] and Bessie splashes it with color 4, the snowball will then have colors [1,2,3,4]. After splashing the snowballs some number of times, Bessie may also want to know how colorful a part of her snow-cow is. The \"colorfulness\" of a snowball x is equal to the number of distinct colors c such that snowball x is colored c. If Bessie asks you about snowball x, you should reply with the sum of the colorfulness values of all snowballs in the subtree of x. Please help Bessie find the colorfulness of her snow-cow at certain points in time.";
for(auto x:text)
x.calcweight();
cout<<gettextstring(-10000);
// WARNING: Huffman will CRASH if you pass a string with only one unique /*aracter
/*string orig = "test1234";
vector<bool> enc = huffman::encode(orig);
string dec = huffman::decode(enc);
if (orig != dec) {
cout << "Not a match!\n";
cout << "Not a match!\n";
}
else {
cout << dec << '\n';
@ -185,6 +206,6 @@ int main() {
cout << '\n';
cout << "Original length: " << orig.size() << '\n';
cout << "Compressed length: " << (enc.size() + 7) / 8 << '\n';
cout << "Percent compression: " << 1.0 - (double)(enc.size() + 7) / 8 / orig.size() << '\n';
cout << "Percent compression: " << 100.0 - (double)100.0 * (enc.size() + 7) / 8 / orig.size() << "%\n";
}*/
}