码迷,mamicode.com
首页 > 其他好文 > 详细

个人项目词频统计2

时间:2016-09-14 12:55:07      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

SSH:git@git.coding.net:shenbaishan/cipintongji_.git

 

 

 1 #pragma warning (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 namespace std;
10 
11 unsigned long Total;
12 class String
13 {
14 public:
15     String(char *Word) :Frequency(1)
16     {
17 
18         Word_Point = new char[strlen(Word) + 1];
19         strcpy(Word_Point, Word);
20     }
21     char *Word_Point;
22     int Frequency;
23     bool operator<(String STR);
24     ~String(){}
25 };
26 
27 bool String::operator<(String STR){ return Frequency < STR.Frequency; }
28 
29 vector<String>  Sort_Word;
30 
31 void If_Repet(char *WordP)
32 {
33     vector<String>::iterator iter;
34     for (iter = Sort_Word.begin(); iter != Sort_Word.end(); iter++)
35     if (!strcmp(iter->Word_Point, WordP))
36     {
37         Total++;
38         iter->Frequency++;
39         return;
40     }
41     Sort_Word.push_back(String(WordP));
42 }
43 
44 void Catch_Letter(char *File_P)
45 {
46     char *Wor_Po = (char *)malloc(4);
47     FILE *Article = fopen(File_P, "r");
48     char *Letter_Point;
49     while (!feof(Article))
50     {
51         fscanf(Article, "%s", Wor_Po);
52         Letter_Point = Wor_Po;
53         while (*Letter_Point++)
54         {
55             if (*Letter_Point == , || *Letter_Point == .)
56                 *Letter_Point = 0;
57         }
58         If_Repet(Wor_Po);
59     }
60 }
61 
62 void Stat_Alone(char *Master_P)
63 {
64         Catch_Letter(Master_P);
65         sort(Sort_Word.begin(), Sort_Word.end());
66         cout << "total :" << Total << endl << endl;
67         for (vector<String>::iterator iter = Sort_Word.begin(); iter != Sort_Word.end(); iter++)
68             printf("Word : %-15s Frequency :%d\n", iter->Word_Point, iter->Frequency);
69         Total = 0;
70         Sort_Word.clear();
71 }
72 
73 void main(int argv ,char **argc)
74 {
75     time_t start = clock();
76     if (strcmp(argc[1], "folder"))    Stat_Alone(argc[1]);
77     else
78     {
79         char *Folder = (char *)malloc(40*sizeof(int));
80         FILE *Folder_P = fopen("folder.txt" ,"r");
81         while (!feof(Folder_P))
82         {
83             if (feof(Folder_P)) break;
84             
85             fscanf(Folder_P, "%s", Folder);
86             Stat_Alone(strcat(Folder, "\\article.txt"));
87         }
88     }
89     printf("Use time: %.0f ms" ,double(clock() - start)*1000/CLOCKS_PER_SEC);
90     getchar();
91 }

功能1

技术分享 

功能3

技术分享

功能4

技术分享

实现了部分功能。功能2还不行

个人项目词频统计2

标签:

原文地址:http://www.cnblogs.com/shenbaishan/p/5871105.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!