HDOJ.1263 水果(map)
2024-08-24 07:56:52
水果
题意分析
给出多组测试数据,每组数据有多条信息。分别是水果种类,地点,和水果数目。每组信息要按照样例输出,并且输出要按照地点->水果种类的字典序。
可以采用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);
}
最新文章
- sqlserver text/ntext 字段读取
- 启用apache,发现80端口被占用【已解决】
- Monkey for iOS(CrashMonkey4IOS)
- 第十六回 IoC组件Unity续~批量动态为Unity添加类型和行为
- swift学习笔记之-函数
- mysql登陆报错(ERROR 2002 (HY000): Can&#39;t connect to local MySQL server through socket &#39;/var/lib/mysql/mysql.sock&#39; (2))
- Learning WCF Chapter2 Messaging Protocols
- 关于web标准的理解(转)
- [转]C/C++:构建你自己的插件框架
- IndentationError: unexpected indent
- org.apache.jasper.JasperException
- jquery的动画学习--jquery权威指南
- YII2框架下使用PHPExcel导出柱状图
- Asp.Net Core配置Swagger
- Jvm 内存模型 —— GC
- Day3 -4.9!受到毕设的突然袭击,一脸蒙蔽,学习暂时停止,明晚继续
- 14.Scrapy Shell
- Linux中符号总结
- C++ map中使用erase应该注意到的问题
- JS部分
热门文章
- uvaoj 10474 - Where is the Marble?(sort+lower_bound)
- VIN码识别,车架号识别,OCR扫描工具
- Selenium(Python) ddt读取MySQL数据驱动
- [C++]STL中的容器
- Visual Stdio Code编辑Mark Down
- UVa 10082 - WERTYU 解题报告 - C语言
- 四、oracle 用户管理二
- 从hive导入到oracle(Hcatalog)
- 第三课——MFC编程
- Internet History