From add9d810d563d73490c95840ce73c067ceb2fbab Mon Sep 17 00:00:00 2001 From: wuyouZen <18010679387@163.com> Date: Sat, 14 Apr 2018 22:31:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=B0=8F=E5=BB=BA=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- count.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) 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 "<