首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++兑现从键盘输入一段文字(中文)后,对其中某个词语次数统计

2012-08-08 
C++实现从键盘输入一段文字(中文)后,对其中某个词语次数统计各位高手帮帮忙,是输入的中文,最好输入后保存

C++实现从键盘输入一段文字(中文)后,对其中某个词语次数统计
各位高手帮帮忙,是输入的中文,最好输入后保存在一个文本文件中,给我一个完整的程序,尽量语言简单点,我学的比较基础

[解决办法]
这个问题没有说清,输入一句话如何划分词呢?底下程序使用空格断开的!先将就着用吧!

C/C++ code
#include <iostream>#include <fstream>#include <string>#include <algorithm>#include <cctype>   #include <map>using namespace std;void main(void)              {    string str;    map<string,int> string_count ;            while(cin>>str){        if(str!="."&&str!=","){  // 去掉 标点符号 暂定为只有.与,                        ++string_count[str];        }            }        map<string,int>::iterator it=string_count.begin();        cout<<"字符串"<<"  "<<"出现次数"<<endl;    while(it!=string_count.end()){            cout<<it->first<<"     "<<it->second<<endl;        it++;    }    }
[解决办法]
仅供参考,尽管是VB6
VB code
Private Sub Form_Load()Dim sentence As StringDim words As StringDim WordApp As Object    sentence = "请对您的言行负责,并遵守中华人民共和国有关法律法规,尊重网上道德。"    words = ""    Set WordApp = CreateObject("Word.Application")    WordApp.Documents.Add    WordApp.Selection.TypeText Text:=sentence    WordApp.Selection.HomeKey    Do        WordApp.Selection.MoveRight Unit:=2, Count:=1, Extend:=1        If WordApp.Selection.Text = vbCr Then Exit Do        words = words + WordApp.Selection.Text + vbCrLf        WordApp.Selection.MoveRight Unit:=1, Count:=1    Loop    WordApp.Quit SaveChanges:=0    Set WordApp = Nothing    MsgBox words    EndEnd Sub 

热点排行