SSH:[email protected]: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还不行
时间: 2024-11-06 12:44:00