Home > Back-end >  C STL experiment given article word frequency statistics according to the word order
C STL experiment given article word frequency statistics according to the word order

Time:12-01

Requirements:
1. Ignore case
2. Ignore the Numbers
3. The abbreviations and combination word processing
4. Utf-8 processing
Requirements of the third don't know how to realize there is no train of thought, the fourth request don't know what to do, I good food
In a couple of days experiment to hand in the homework
The ball ball everyone help thank you! Thank you thank you!

Completed code:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;

The class cword {
Private:
The string word;
Public:
Cword (string s) : the word (s) {}
Const string getword () {
The return of word;
}
Bool operator<(const cword& C) const {//set the map the default sort for ascending overloading & lt;
Return word}
};


The class cwordset {
Private:
Set Wordset;
Public:
Void the add (string s) {
Wordset. Insert (cword (s));
}
Void show (ostream& OS) {
Set : : iterator it=wordset. The begin ();
Int n=0;
While (it!=wordset. End ()) {
Os<(* it). Getword () & lt; <" ";
It++;
If (8 + + n %==0) {
OsN=0;
}
}
}
};

The class cwordmap {
Private:
Map Wordmap;
Public:
Void the add (string s) {
Map : : iterator it=wordmap. Find (s);
If (it==wordmap. End ()) {
Pair P (cword (s), 1);
Wordmap. Insert (p);
}
The else {
(it - & gt; Second) +=1;
}
}
Void show (ostream& OS) {
Map : : iterator it=wordmap. The begin ();
While (it!=wordmap. End ()) {
Os<" Word: "& lt; <((* it). First). Getword () & lt; <" Number: "& lt; <(* it). SecondIt++;
}
}
Map The getmap () {
Return this - & gt; Wordmap;
}
};

Bool CMP (pair P1, pair P2) {
Return p1. Second}
/* bool cmp1 (pair P1, pair P2) {
If (p1) second==p2) second)
Return (p1) first.) getword () & lt; (p1. First). Getword ();
} */

Int main ()
{
Cwordset wordset;
Cwordmap wordmap;

string s;
String deletess=",. () [] :;" "' + - */1234567890";
Ifstream iff (" Java (2). The HTML ");

While (getline (iff, s)) {
//coutIf (s=="") continue;
Int pos=0;
While ((pos=s. ind_first_of (deletess, pos))!=the string: : npos)
S.r eplace (pos, 1, "");

for(int i=0; iS=tolower [I] [I] (s);//uppercase lowercase
}

Stringstream stringm (s);
while(! Stringm. Eof ()) {
String SSS;
Stringm & gt;> SSS;
If (SSS=="") continue;
Wordset. Add (SSS);
Wordmap. Add (SSS);
}
}
Iff. Close ();

//wordset. Show (cout);
CoutWordmap. Show (cout);
Cout

Map My_map (wordmap. The getmap ());
Vector v;
Map : : iterator it=my_map. The begin ();
For (it; it!=my_map. End (); It++) {
//Valerie plame ush_back (pair (it - & gt; First, it - & gt; Second));
* back_inserter (v)=pair (it - & gt; First, it - & gt; Second);
//cout<(it - & gt; First). Getword () & lt; <" "& lt; }

//vector V ((wordmap. The getmap ()). The begin (), (wordmap. The getmap ()). The end ());
/* vector v;
Map : : iterator it=(wordmap. The getmap ()). The begin ();
For (it; it!=(wordmap. The getmap ()). The end (); It++) {
//Valerie plame ush_back (pair (it - & gt; First, it - & gt; Second));
* back_inserter (v)=pair (it - & gt; First, it - & gt; Second);
Cout<(it - & gt; First). Getword () & lt; <" "& lt; } */

Sort (what exactly do v.begin (), v.e nd (), CMP);//the value by the
Vector : : iterator n=what exactly do v.begin ();
For (vt. Vt.=v.e nd (); Vt++) {
Cout<(n - & gt; First). Getword () & lt; <" : "& lt; }
}



File name: Java (2). The HTML
null
  • Related