Individual project Word frequency Statistics 2

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.