Advertisement

C++第三章批处理数据

阅读量:

3-3 编写程序计算其输入内容中各个单词的出现频次

逻辑1:对输入的单词进行逐个处理,若当前单词已存在则对应的计数器加1;若为新单词,则将其加入栈结构并同时使计数向量的长度增加1。

逻辑2:将所有输入的单词统一存入vector容器中,随后进行排序操作,再依次进行对比分析。

复制代码
 //统计输入中不同单词的个数

    
 #include <iostream>
    
 #include <string>
    
 #include <vector>
    
  
    
 using namespace std;
    
  
    
 int main() {
    
 	typedef vector<string>::size_type vec_sz;
    
  
    
 	vector<string> words;
    
 	vector<int> count;
    
  
    
 	cout << "input your words"
    
 		"followed by end-of-file";
    
 	string word;
    
  
    
 	//读入数据
    
 	while (cin >> word) {
    
 		bool found = false;
    
 		for (ve

全部评论 (0)

还没有任何评论哟~