zoukankan
html css js c++ java
c++ 从文件中读取字符串 按字典排序 并统计个数
#include <vector> #include <string> #include <algorithm> #include <iostream> #include <iterator> #include <map> #include <fstream> using namespace std; const int MAX_SIZE = 40; void GetWords(vector<string> &vec) { char str[ MAX_SIZE]; ifstream InFile("E:\\test.txt"); while(!InFile.eof()) { InFile.getline(str,MAX_SIZE); const char * split = ",* ;"; char * p; p = strtok (str,split); while(p!=NULL) { string str = p; vec.push_back(str); p = strtok(NULL,split); } } copy (vec.begin(),vec.end(),ostream_iterator<string>(cout," ")); } void SortWords( vector<string> &vec,map<string,int> &words) { vector<string>::iterator it = vec.begin(); for(it; it != vec.end(); ++it) { if(words.find(*it) != words.end() ) { int i = words[*it]; ++i; words[*it] = i; } else { words.insert(map<string,int>::value_type(*it,1)); } } } int _tmain(int argc, _TCHAR* argv[]) { vector<string> vec; map<string,int> words; GetWords(vec); SortWords( vec,words); cout<<endl<<"====After sort===="<<endl; map<string,int>::iterator mapit = words.begin(); for(mapit;mapit != words.end();++mapit) { cout<< mapit->first<<" "<<mapit->second<<endl; } return 0; }
查看全文
相关阅读:
smart client优势在那里? (草稿)
MSN to expand free email storage to 250MB
转移阵地了,新地址:http://spaces.msn.com/members/PuGong
关于XMLHTTP object的OPEN方法
创建第一个Windows Phone应用程序(一)
Windows 平台下安装Cygwin后,sshd服务无法启动
ASP.NET MVC3 Use Remote Validation
ASP.NET MVC3中使用AllowHtml attribute
HTML5 Canvas实现简单的俄罗斯方块
创建第一个Windows Phone应用程序(二)
原文地址:https://www.cnblogs.com/dyufei/p/2573900.html
最新文章
转:复杂的1秒 图解Google搜索技术
转:名站技术分析 — facebook奇特的页面加载技术
转:Discuz!NT数据库读写分离方案
转:Discuz!NT跨站缓存同步
转:大规模网站架构之WEB加速器SQUID(二)
转:海纳百川——人人网海量存储系统Nuclear开发手记
转:系统架构师基础到企业应用架构
转:解密超强大的Facebook数据中心
转:Google的系统工程师(SA)如何工作
转:Discuz!NT负载均衡解决方案(HA)之LVS(Linux Virtual Server)
热门文章
转:想留住用户,就要让他们能容易地离开
POJ 1002 电话号码
typedef
hdu 1896 Stones
Harry Potter The HalfBlood Prince
SQL Server的collation问题
Microsoft Interview Question links 转自http://blogs.msdn.com/chappell/archive/2004/07/20/189364.aspx
用 #inculde file = "../fiel" 报1031错误
用 报错误1031
Excel programming (C# + VBA) Part 1
Copyright © 2011-2022 走看看