diff --git a/count.cpp b/count.cpp index 303e330..f325d8f 100644 --- a/count.cpp +++ b/count.cpp @@ -1,4 +1,4 @@ -// count.cpp : 定义控制台应用程序的入口点。 +// count.cpp : 瀹氫箟鎺у埗鍙板簲鐢ㄧ▼搴忕殑鍏ュ彛鐐广 // #include "stdafx.h" @@ -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; @@ -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(100); @@ -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') @@ -64,7 +65,7 @@ void count(string s) { if (s[i] == 32) { - //把遇到的第一个单词放在result中 + //鎶婇亣鍒扮殑绗竴涓崟璇嶆斁鍦╮esult涓 result.append(s, record, i - record); while (s[i] == 32) { @@ -72,7 +73,7 @@ void count(string s) } s = s.substr(i, s.size()); i = 0; - //查找s中是否还有该单词,找到则从s中删除 + //鏌ユ壘s涓槸鍚﹁繕鏈夎鍗曡瘝锛屾壘鍒板垯浠巗涓垹闄 //cout << s << " before "<