【HDU1263 水果】 STL之map应用经典好题
2013-04-17 17:46
218 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263
题目大意:对同一地方的同一水果进行归类。
解题思路: map真心强大,以前只知道map的一维运用,今天了解了map的二维运用(map映射map)。
View Code
题目大意:对同一地方的同一水果进行归类。
解题思路: map真心强大,以前只知道map的一维运用,今天了解了map的二维运用(map映射map)。
View Code
#include <iostream> #include <cstdio> #include <cstring> #include <map> #include <algorithm> using namespace std; int main() { int T, m; cin >> T; while(T--) { map<string,map<string,int> >mp; ///注意格式 string place, name; int num; cin >> m; for(int i=0; i<m; i++) { cin >> name >> place >> num; mp[place][name]+=num;; } for(map<string,map<string,int> >::iterator iter1=mp.begin(); iter1!=mp.end(); iter1++) ///第一关键字(map里居然会自动排序,难道和hash表一样的?真心感觉自己肤浅) { cout << iter1->first <<endl; for(map<string,int >::iterator iter2=iter1->second.begin(); iter2!=iter1->second.end(); iter2++) ///第二关键字 cout << " |----" << iter2->first << "(" << iter2->second << ")" <<endl; } if(T) cout << endl; } return 0; }
相关文章推荐
- 【HDU1263】【STL-MAP套MAP】(省份,水果,数量)MAP嵌套大开发
- hdu4585(STL的map应用)
- STL中map的简单应用(合并表序列)
- hdu1004 Let the Balloon Rise && hdu1263 水果(map)
- 温故篇之STL_map,set的一些应用
- STL中map和priority_queue的应用
- STL之map应用 +hash表(51nod 1095)
- STL 应用一(MAP)
- sicily 1194 Message Flood (STL的map和set应用练习)
- POJ 2418 Hardwood Species(STL在map应用)
- STL之map应用 回文串
- PAT QQ帐户的申请与登陆 STL-MAP的应用
- STL-set,map基础应用
- ACM: STL标准库容器的应用(vector、queue、list、map)
- Problem A: STL—水果店(map见解及实例应用)
- POJ 2418 Hardwood Species(STL中map的应用)
- UVA 10420-List of Conquests(STL-map的应用)
- STL模版库的vector,map的简单应用
- HDU 1263 水果(map的简单应用)
- C++抽象编程——STL实战(5)——map在数据文件查找中的应用