首页 > 其他 > 详细

vj map

时间:2020-07-19 14:16:56      阅读:36      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 技术分享图片

 

 

 1 /*
 2  * 换行好烦人呀!
 3  */
 4 #include <iostream>
 5 #include <map>
 6 #include <string>
 7 using namespace std;
 8 map<string,map<string,int>> m;
 9 int N;
10 int main() {
11     cin >> N;
12     while (N--) {
13         int n;
14         cin>>n;
15         for (int i = 0; i < n; ++i) {
16             string place, fruit;
17             int q;
18             cin >> fruit >> place;
19             cin >> q;
20             m[place][fruit] += q;//cin以后储存,再把地名放在前面
21         }
22         for (map<string, map<string, int>>::iterator i = m.begin(); i != m.end(); i++) {
23             cout << i->first << endl;
24             for (map<string, int>::iterator j = (i->second).begin(); j != (i->second).end(); j++) {
25                 cout << "   |----" << j->first << "(" << j->second << ")" <<endl;
26 
27             }
28 
29         }
30 
31         m.clear();//最后别忘了清空!!!
32         if (N)
33             cout <<endl;
34     }
35 }

 

vj map

原文:https://www.cnblogs.com/zhmlzhml/p/13339301.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!