Ssh:[email Protected]:shenbaishan/cipintongji_.git
1 #pragmaWarning (disable:4996)2#include <iostream>3#include <map>4#include <vector>5#include <algorithm>6#include <string.h>7#include <time.h>8 9 using namespacestd;Ten OneUnsignedLongTotal ; A classString - { - Public: theString (Char*word): Frequency (1) - { - -Word_point =New Char[Strlen (Word) +1]; + strcpy (Word_point, Word); - } + Char*Word_point; A intFrequency; at BOOL operator<(String STR); -~String () {} - }; - - BOOLString::operator< (String STR) {returnFrequency <STR. Frequency; } - inVector<string>Sort_word; - to voidIf_repet (Char*wordp) + { -Vector<string>:: iterator iter; the for(iter = Sort_word.begin (); ITER! = Sort_word.end (); iter++) * if(!STRCMP (iter->Word_point, WORDP)) $ {Panax Notoginsengtotal++; -iter->frequency++; the return; + } A Sort_word.push_back (String (WORDP)); the } + - voidCatch_letter (Char*file_p) $ { $ Char*wor_po = (Char*)malloc(4); -FILE *article = fopen (file_p,"R"); - Char*Letter_point; the while(!feof (article)) - {WuyiFSCANF (article,"%s", WOR_PO); theLetter_point =Wor_po; - while(*letter_point++) Wu { - if(*letter_point = =','|| *letter_point = ='.') About*letter_point =0; $ } - If_repet (WOR_PO); - } - } A + voidStat_alone (Char*master_p) the { - Catch_letter (master_p); $ sort (Sort_word.begin (), Sort_word.end ()); thecout <<"Total:"<< Total << Endl <<Endl; the for(Vector<string>::iterator iter = Sort_word.begin (); ITER! = Sort_word.end (); iter++) theprintf"Word:%-15s Frequency:%d\n", Iter->word_point, iter->Frequency); theTotal =0; - sort_word.clear (); in } the the voidMainintArgvChar**argc) About { thetime_t start =clock (); the if(strcmp (argc[1],"folder")) Stat_alone (argc[1]); the Else + { - Char*folder = (Char*)malloc( +*sizeof(int)); theFILE *folder_p = fopen ("Folder.txt","R");Bayi while(!feof (folder_p)) the { the if(Feof (folder_p)) Break; - -FSCANF (Folder_p,"%s", Folder); theStat_alone (strcat (Folder,"\\article.txt")); the } the } theprintf"Use time :%.0f Ms",Double(Clock ()-start) * +/clocks_per_sec); - GetChar (); the}
Function 1
Function 3
Function 4
Some functions are implemented. Function 2 not yet.
Individual project Word frequency Statistics 2