水果

点我跳转到题面

点我一起学习STL-MAP

题意分析

给出多组测试数据,每组数据有多条信息。分别是水果种类,地点,和水果数目。每组信息要按照样例输出,并且输出要按照地点->水果种类的字典序。

可以采用map的嵌套,来实现题目要求。但要注意一下,在循环的时候迭代器内外层是的类型是不一样的,所以要重新写两种typedef。

(此题也是学习了别的大牛的做法,这题有结构体排序也可以是实现)

代码总览

/*
Title:HDOJ.1263
Author:pengwill
Date:2016-11-21
*/
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
using namespace std;
string s1,s2;
int main()
{
//freopen("in.txt","r",stdin);
typedef map<string,map<string,int> > mmp;
typedef map<string,int> mp;
mmp p;
int t,n,num,flag = 0;
cin>>t;
while(t--){
p.clear();
cin>>n;
while(n--){
cin>>s2>>s1>>num;
p[s1][s2]+=num;
}
mmp::iterator iter1;
mp::iterator iter2;
for(iter1 = p.begin(); iter1!= p.end();iter1++){
cout<<iter1->first<<endl;
for(iter2 = iter1->second.begin();iter2 != iter1->second.end();iter2++){
cout<<" |----"<<iter2->first<<"("<<iter2->second<<")"<<endl;
}
}
if(t){
cout<<endl;
}
} return 0;
//fclose(stdin);
}

最新文章

  1. sqlserver text/ntext 字段读取
  2. 启用apache,发现80端口被占用【已解决】
  3. Monkey for iOS(CrashMonkey4IOS)
  4. 第十六回 IoC组件Unity续~批量动态为Unity添加类型和行为
  5. swift学习笔记之-函数
  6. mysql登陆报错(ERROR 2002 (HY000): Can&#39;t connect to local MySQL server through socket &#39;/var/lib/mysql/mysql.sock&#39; (2))
  7. Learning WCF Chapter2 Messaging Protocols
  8. 关于web标准的理解(转)
  9. [转]C/C++:构建你自己的插件框架
  10. IndentationError: unexpected indent
  11. org.apache.jasper.JasperException
  12. jquery的动画学习--jquery权威指南
  13. YII2框架下使用PHPExcel导出柱状图
  14. Asp.Net Core配置Swagger
  15. Jvm 内存模型 —— GC
  16. Day3 -4.9!受到毕设的突然袭击,一脸蒙蔽,学习暂时停止,明晚继续
  17. 14.Scrapy Shell
  18. Linux中符号总结
  19. C++ map中使用erase应该注意到的问题
  20. JS部分

热门文章

  1. uvaoj 10474 - Where is the Marble?(sort+lower_bound)
  2. VIN码识别,车架号识别,OCR扫描工具
  3. Selenium(Python) ddt读取MySQL数据驱动
  4. [C++]STL中的容器
  5. Visual Stdio Code编辑Mark Down
  6. UVa 10082 - WERTYU 解题报告 - C语言
  7. 四、oracle 用户管理二
  8. 从hive导入到oracle(Hcatalog)
  9. 第三课——MFC编程
  10. Internet History