Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions count.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// count.cpp : �������̨Ӧ�ó������ڵ㡣
// count.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
Expand All @@ -18,13 +18,13 @@ class Save
};

bool comparison(Save a, Save b) {
//��������>
//降序排列>
return a.number>b.number;
}
string readFileIntoString()
{
ifstream ifile;
//�ȶ��뵽buf
//先读入到buf
ifile.open("d:\\words.txt");
ostringstream buf;
char ch;
Expand All @@ -35,14 +35,15 @@ string readFileIntoString()
return buf.str();
}

//这个函数有点太长了,能否尝试分解一下。而且它的名字也没有准确反应它的功能。
void count(string s)
{
string result;
//record��¼��������ĸ
//record记录单词首字母
int record = 0;
//number��¼���ʳ��ִ���
//number记录单词出现次数
int number = 1;
//ɾ����ͷ�Ŀո�
//删除开头的空格
int i = 0;
int numOfWord = 0;
vector <Save> save(100);
Expand All @@ -51,7 +52,7 @@ void count(string s)
i++;
}
s = s.substr(i, s.size());
//����ת��Ϊ�ո�
//换行转化为空格
for (int i = 0; i < s.size(); i++)
{
if (s[i] == '\n')
Expand All @@ -64,15 +65,15 @@ void count(string s)
{
if (s[i] == 32)
{
//�������ĵ�һ�����ʷ���result��
//把遇到的第一个单词放在result中
result.append(s, record, i - record);
while (s[i] == 32)
{
i++;
}
s = s.substr(i, s.size());
i = 0;
//����s���Ƿ��иõ��ʣ��ҵ����s��ɾ��
//查找s中是否还有该单词,找到则从s中删除
//cout << s << " before "<<endl;
int pos;
while ((pos = s.find(result)) != string::npos)
Expand All @@ -95,7 +96,7 @@ void count(string s)
result = "";
number = 1;
}
//�������һ������
//处理最后一个单词
if (i == s.size() && s != "")
{
//cout << s << " " << "1" << endl;
Expand Down