【HDOJ】1263 水果
hash,使用stl map ac。学了find_if等强大的东西,第一次使用stl模板。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
using namespace std; #define NAMENUM 25 typedef struct fruit_st {
char name[NAMENUM];
char produce[NAMENUM];
bool operator < (const fruit_st &a) const {
if (strcmp(produce, a.produce))
return strcmp(produce, a.produce)> ? false : true;
else
return strcmp(name, a.name)> ? false : true;
}
} fruit_st; class map_finder {
public:
map_finder(const fruit_st a) {
strcpy(fruit.name, a.name);
strcpy(fruit.produce, a.produce);
}
bool operator ()(const map<fruit_st, int>::value_type &pair) {
if (strcmp(fruit.name, pair.first.name)== && strcmp(fruit.produce, pair.first.produce)==)
return true;
else
return false;
}
private:
fruit_st fruit;
}; int main() {
map<fruit_st, int> sale_info;
map<fruit_st, int>::iterator iter;
fruit_st fruit;
int case_n, n, num; scanf("%d", &case_n); while (case_n--) {
scanf("%d", &n);
while (n--) {
scanf("%*c%s %s %d", fruit.name, fruit.produce, &num); iter = find_if(sale_info.begin(), sale_info.end(), map_finder(fruit));
if (iter == sale_info.end()) {
sale_info.insert(make_pair(fruit, num));
//sale_info[fruit] = num;
}else
iter->second += num;
}
for (map<fruit_st, int>::iterator ii=sale_info.begin(); ii!=sale_info.end(); ++ii) {
if (ii != sale_info.begin()) {
if (strcmp(ii->first.produce, iter->first.produce))
printf("%s\n", ii->first.produce);
printf(" |----%s(%d)\n", ii->first.name, ii->second);
} else {
printf("%s\n", ii->first.produce);
printf(" |----%s(%d)\n", ii->first.name, ii->second);
}
iter = ii;
}
sale_info.clear();
if (case_n)
printf("\n");
} return ;
}
【HDOJ】1263 水果的更多相关文章
- HDOJ.1263 水果(map)
水果 点我跳转到题面 点我一起学习STL-MAP 题意分析 给出多组测试数据,每组数据有多条信息.分别是水果种类,地点,和水果数目.每组信息要按照样例输出,并且输出要按照地点->水果种类的字典序 ...
- hdu 1263 水果 【二维map】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263 题目大意: Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ ...
- 题解报告:hdu 1263 水果
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263 Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营 ...
- hdu 1263 水果
Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样J ...
- HDU 1263(水果统计 **)
题意是对水果的产地和种类进行统计再按格式输出. 代码如下: #include <bits/stdc++.h> using namespace std; struct node { ],pl ...
- hdu 1263 水果 结构的排序+sort自定义排序
水果 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...
- HDU 1263 水果 结构体排序
解题报告:一个结构体排序的题,用了一个运算符重载,要注意的是不同的地方可能会产相同的水果,一开始没注意. #include<cstdio> #include<cstring> ...
- hdu 1263 水果 (嵌套 map)
水果Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissio ...
- HDU 1263 水果 (STL map)
水果 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...
随机推荐
- (已实现)相似度到大数据查找之Mysql 文章匹配的一些思路与提高查询速度
需求,最近实现了文章的原创度检测功能,处理思路一是分词之后做搜索引擎匹配飘红,另一方面是量化词组,按文章.段落.句子做数据库查询,功能基本满足实际需求. 接下来,还需要在海量大数据中快速的查找到与一句 ...
- 粵語/廣東話/Cantonese 資料/Material
一.粵語歌詞網 1.海闊天空(粵語) 歌詞 今天我 寒夜裡看雪飄過 gam1 tin1 ngo5 hon4 je6 leoi5 hon3 syut3 piu1 gwo3 懷著冷卻了的心窩漂遠方 waa ...
- 安装ipython notebook
从http://cs231n.github.io/assignments2016/assignment1/开始说起,因为要学习cs231n课程,需要安装ipython notebook,原本电脑中安装 ...
- C++对象模型与内存位对齐的简单分析(GNU GCC&VS2015编译器)
以Fruit和Apple为例进行分析: Fruit和Apple的定义如下: 通过在两种编译环境下的测试(GNU GCC & VS2015),可以发现这两种编译器的对象模型是一样的,如下图所示: ...
- Poj 1006 / OpenJudge 2977 1006 Biorhythms/生理周期
1.链接地址: http://poj.org/problem?id=1006 http://bailian.openjudge.cn/practice/2977 2.题目: Biorhythms Ti ...
- sql server 2008数据复制方法
发布订阅份为两个步骤:1.发布.2.订阅.首先在数据源数据库服务器上对需要同步的数据进行发布,然后在目标数据库服务器上对上述发布进行订阅.发布可以发布一张表的部分数据,也可以对整张表进行发布.下面分别 ...
- mui 重写back 调用back方法,实现返回就即时刷新页面
需求: 从A-----b页面 B操作完后再返回A ,这时A页面数据变化 1.先是针对安卓机可以点击按钮返回,也可以用本机的返回键返回 监听本机的返回按钮,如果点击就调用写好的自定义刷新事件 (fun ...
- AngularJS(2)-Scope作用域和控制器
$scope: 根作用域 所有的应用都有一个 $rootScope,它可以作用在 ng-app 指令包含的所有 HTML 元素中. $rootScope 可作用于整个应用中.是各个 controlle ...
- putty实现自动登录的方法(ssh和ssh2)
介绍putty实现自动登录的方法. 1.登录主机并输入ssh-keygen -t rsa 提示Enter file in which to save the key (/root/.ssh/id ...
- php socket connect permission denied
Linux在php socket连接时报错:permission denied 解决办法: # setsebool httpd_can_network_connect=1 参考来源: http://w ...