HDU 1263 水果(map的简单应用)
2017-08-18 19:33
507 查看
直接上AC代码:
#include<iostream> #include<map> #include<string> using namespace std; int main(){ int t; scanf("%d", &t); while(t--){ int n; scanf("%d",&n); map<string, map<string, int> > mp;//可以理解为二维的map,有两个key,一个value map<string, map<string, int> >:: iterator it1; map<string, int>:: iterator it2; string place, fruit; int number; for(int i = 1; i <= n; i++){ cin>>fruit>>place>>number; mp[place][fruit] += number; } for(it1 = mp.begin(); it1 != mp.end(); it1 ++){ cout<<(*it1).first<<endl; for(it2 = (*it1).second.begin(); it2 != (*it1).second.end(); it2++){ cout<<" |----"<<(*it2).first<<"("<< (*it2).second <<")"<<endl; //注意一下输出格式 } } // it2 = (*it1).second.begin(); 可以写成 it2 = it1->second.begin(); if(t) cout<<endl; } return 0; }
相关文章推荐
- HDU-1263 水果(map)
- hdu 2072 单词数(map的简单应用)
- hdu-1247 简单map的应用。(字典树)
- hdu 1263 水果(map)
- hdu 1263 水果 map的双重用法 超级帅呆 重要哦
- hdu 4287 Intelligent IME map的简单应用
- HDU--1263--水果(map迭代使用)
- HDU 1263 水果(map或结构体排序)
- STL_map简单应用(HDU_1075)
- hdu 1263 水果(map)
- HDU-1263 水果(STL:map)
- hdu 1263 水果(map)
- HDU 1263 水果 map容器
- HDU1263_水果_stl的map的嵌套用法
- hdu 1263 水果 (二维map)
- hdu 2648(map简单应用)
- hdu 2648(map简单应用)
- HDU 2222 最简单的AC自动机套模板应用
- hdu 1237简单计算器(栈的简单应用)
- HDU 1247 Hat’s Words(字典树简单应用)