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

(使用STL自带的排序功能7.1.1)POJ 2418 Hardwood Species(地图的定义、访问、迭代)

2013-11-03 
(使用STL自带的排序功能7.1.1)POJ 2418 Hardwood Species(map的定义、访问、迭代)/* * POJ_2418.cpp * *Crea

(使用STL自带的排序功能7.1.1)POJ 2418 Hardwood Species(map的定义、访问、迭代)

/* * POJ_2418.cpp * *  Created on: 2013年10月31日 *      Author: Administrator */#include <iostream>#include <cstdio>#include <map>//map默认按字典序进行排序#include <string>using namespace std;int main(){map<string,int> mp;//map的定义string str;int cnt = 0;while(getline(cin,str)){//使用getline()记得要#include<string>cnt++;mp[str]++;//map的使用}//map的迭代for(map<string,int>::iterator it = mp.begin() ; it != mp.end() ;++it){string name = (*it).first;int k = (*it).second;printf("%s %.4lf\n",name.c_str(),double(k)/cnt*100);//c++风格的字符串输出时要.c_str()转化一下}return 0;}

热点排行