G - 水果(HDU - 1263)

- 题目大意

将每个产地的水果种类和数量按照字典序输出。

- 解题思路

利用一个二维的map容器将它的产地,品种,数目记录即可。(注意第一维以产地为键,水果为值,第二维以水果类型为键,水果数量为值,就可以自动按照字典序排序了。)。

- 代码

#include<iostream>
#include<map>
#include<string>
using namespace std;

int main()
{
	int m, n;
	string nam, adr;
	int ber;
	cin >> m;
	while (m--)
	{
		map<string, map<string, int>>fr;
		cin >> n;
		while (n--)
		{
			cin >> nam >> adr>>ber;
			fr[adr][nam]+=ber;
		}
		map<string,map<string,int>>::iterator i1;
		map<string, int>::iterator i2;
		for (i1 = fr.begin(); i1 != fr.end(); i1++)
		{
			cout << i1->first<<endl;
			for (i2 = (i1->second).begin(); i2 != (i1->second).end(); i2++)
			{
				cout << "   |----" << i2->first << "(" << i2->second << ")" << endl;
			}
		}
		fr.clear();
		if(m!=0)
		cout << endl;
	}
	return 0;
}

  

原文地址:https://www.cnblogs.com/alpacadh/p/8438523.html

时间: 2025-02-01 22:47:07

G - 水果(HDU - 1263)的相关文章

HDU 1263

第一次写map的嵌套 和less<>的排序 #include <map> #include <cstdio> #include <iostream> #include <string.h> #include <cstring> #include <string> using namespace std; map<string,map<string,int>,less<string> >

题解报告:hdu 1263 水果

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263 Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容易掌握所有水果的销售情况了. Input 第一行正整数N(0<N<=10)表示有N组测试数据. 每组测试数据的第一行是一个整数M(0<M<=100),表示工有M次成功的

hdu 1263 水果(map)

水果 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3831    Accepted Submission(s): 1433 Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以

Hdu 1263 水果

水果 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6986    Accepted Submission(s): 2748 Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容

hdu 1263 水果 sort对结构体中字符串二级排序

#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; struct node { char name[90],place[90]; int num; }c[105]; bool cmp(node x,node y) { if(strcmp(x.place,y.place)<0) return true; if(strcmp(x.place,y.place)=

G题 hdu 1466 计算直线的交点数

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1466 计算直线的交点数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8799    Accepted Submission(s): 3973 Problem Description 平面上有n条直线,且无三线共点,问这些直线能有多少种不同

HDU 1263 二维map

题意:给出一份水果的交易表,根据地区统计出水果的交易情况. 思路:二维map使用. #include<cstdio> #include<string> #include<map> #include<iostream> using namespace std; map<string,map<string,int> > m; map<string,map<string,int> >::iterator it; ma

【背包专题】G - Dividing hdu 1059【多重背包】

Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they could just split the colle

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&g