map嵌套

第一次使用map嵌套,做个纪念。

HDU 1263 水果

http://acm.hdu.edu.cn/showproblem.php?pid=1263

题解:按照地名的字典序、水果的字典序、水果的数量这个顺序输出。题意很简单,关键是用map嵌套。

代码:

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<cmath>
 5 #include<algorithm>
 6 #include<map>
 7 #define ll long long
 8 using namespace std;
 9 
10 const int N = 105;
11 
12 map<string, map<string, int>, less<string> > q;
13 
14 int main()
15 {
16     std::ios::sync_with_stdio(false);
17     int T;
18     cin >> T;
19 
20     while (T--)
21     {
22         q.clear();
23         int n, m;
24         char fruit[N], province[N];
25         cin >> n;
26         for (int i = 0; i < n; i++)
27         {
28             cin >> fruit >> province >> m;
29             q[province][fruit] += m;
30         }
31         for (auto it = q.begin(); it != q.end(); it++)
32         {
33             cout << it->first << endl;
34             for (auto itt = (it->second).begin(); itt != (it->second).end(); itt++)
35             {
36                 cout << "   |----" << itt->first << "(" << itt->second << ")" << endl;
37             }
38         }
39         if (T)
40             cout << endl;
41     }
42     return 0;
43 }

 

转载于:https://www.cnblogs.com/xiaohanghuo/p/11373761.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值