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; }
查看全文
相关阅读:
warning MSB3245: 未能解析此引用。未能找到程序集“CemeteryBLL”。请检查磁盘上是否存在该程序集。 如果您的代码需要此引用,则可能出现编译错误。
C#MVC中创建多模块web应用程序
Visual Studio提示“无法启动IIS Express Web服务器”的解决方法
未能找到 CodeDom 提供程序类型“Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf385
WebHost failed to process a request.Memory gates checking failed because the free memory (140656640 bytes) is less than 5% of total memory
wamp安装后打开默认网页显示dir,图标红点
数字转为大写,钱转为大写格式
SpringCloud
Spring Boot
双重校验锁 --使用volatile和两次判空校验
原文地址:https://www.cnblogs.com/dyufei/p/2573900.html
最新文章
linux 配置ip
linux c 多线程编程
kali ssh 登录
kali 更新源
Netmask v. Address Prefix Length
虚拟机 不能联网
kali 重置 mysql 密码
kali 安装完成后,无法进入界面
cocos2d-x 血泪史(1.5) 先从helloworld 切换到menu 吧
cocos2d-x 血泪史(-3) winrt 的环境配置单
热门文章
cocos2d-x 血泪史(-2) android 环境配置好之后碰到黑屏!!
cocos2d-x 血泪史(-1) CCNotificationCenter 与LUA
我擦C++ 反人类啊(1)
cocos2d-x 血泪史(1) 先从helloworld 切换到menu 吧
cocos2d-x 血泪史(0) 搭建环境 (只是可以开始写code 看到hello world 粗线的环境)
我擦C++ 反人类啊
那个。。。最近在学cocos2d
身份证号验证
字符串时间转为时间戳,时间戳转为字符串时间
更新edmx文件 无法生成模型:“System.Data.StrongTypingException: 表“TableDetails”中列“IsPrimaryKey”的值为 DBNull
Copyright © 2011-2022 走看看