
STL map题,map中包含map
题目链接HDU 1263
题目大意
告诉你许多水果的名称、产地和数量。先按产地排序,同一产地按名称排序,输出水果明细表。注意二维map的使用方法即可。
AC代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <map> #include <stack> #include <cmath> #include <queue> #include <cstdio> #include <bitset> #include <string> #include <vector> #include <iomanip> #include <cstring> #include <iostream> #include <algorithm> #include <functional> using namespace std; int () { map<string,int>::iterator itmp; map<string,map<string,int> > mpp; map<string,map<string,int> >::iterator itmpp; int n; cin>>n; while(n--) { mpp.clear(); int m; cin>>m; while(m--) { string a,b; int c; cin>>a>>b>>c; mpp[b][a]+=c; } for(itmpp=mpp.begin();itmpp!=mpp.end();itmpp++) { cout<<itmpp->first<<endl; for(itmp=itmpp->second.begin();itmp!=itmpp->second.end();itmp++) { cout<<" |----"<<itmp->first<<"("<<itmp->second<<")"<<endl; } } if(n!=0) { cout<<endl; } } return 0; }
|
近期评论