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 水果的更多相关文章

  1. HDOJ.1263 水果(map)

    水果 点我跳转到题面 点我一起学习STL-MAP 题意分析 给出多组测试数据,每组数据有多条信息.分别是水果种类,地点,和水果数目.每组信息要按照样例输出,并且输出要按照地点->水果种类的字典序 ...

  2. hdu 1263 水果 【二维map】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263 题目大意: Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ ...

  3. 题解报告:hdu 1263 水果

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263 Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营 ...

  4. hdu 1263 水果

    Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样J ...

  5. HDU 1263(水果统计 **)

    题意是对水果的产地和种类进行统计再按格式输出. 代码如下: #include <bits/stdc++.h> using namespace std; struct node { ],pl ...

  6. hdu 1263 水果 结构的排序+sort自定义排序

    水果 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  7. HDU 1263 水果 结构体排序

    解题报告:一个结构体排序的题,用了一个运算符重载,要注意的是不同的地方可能会产相同的水果,一开始没注意. #include<cstdio> #include<cstring> ...

  8. hdu 1263 水果 (嵌套 map)

    水果Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissio ...

  9. HDU 1263 水果 (STL map)

    水果 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

随机推荐

  1. CentOS配置java运行环境

    CentOS_配置_docker CentOS_6.5 1.CentOS_6.5在安装docker-io之前需要首先卸载docker包(没下载过可以省略) $ sudo yum -y remove d ...

  2. 01_Java解析XML

    [打印list.Map集合的工具方法] /** * 打印List集合对应的元素 */ public void printList(List<Object> list){ for(Objec ...

  3. VIM 同义词

    vim-online-thesaurus A Vim plugin for looking up words in an online thesaurus, Now thesaurus.com 一.原 ...

  4. Linux启动提示“unexpected inconsistency;RUN fsck MANUALLY”

    问题:在开机启动时,提示“unexpected inconsistency;RUN fsck MANUALLY”进不了系统 解决方法: fsck不仅可以对文件系统进行扫描,还能修正文件系统的一些问题, ...

  5. debian 学习记录-2 -账户 -关机

    linux考虑系统安全设定了root账号和user账号 权限较低的user账号下,连关机命令都执行不了…… 用户切换... 用户切换1 命令su(在user账号下,即可开启root账号模式) 用户切换 ...

  6. Mac下修改默认的Java版本

    今天在安装Elicpse IDE的时候,发现提示安装的Java版本不支持,于是在官方去下载了Jre最新版本并安装,在安装完过后再次打开Elicpse发现提示还是不正确,如果用Google查询到一些资料 ...

  7. C# Form窗体子窗口关闭时刷新父窗体中的datagridview

    解决该问题可以用委托,但是还有更简单方便的两种方法: 方法一:将主窗体实例保存到子窗体 show  form2的时候设置一下 owner为form1 Form2 f2 = new Form2(); / ...

  8. 服务控件与html标签的一点

    前言 很久没有用服务器控件开发了,在新公司待了三四个月了,这个公司一直都用服务器控件.所以在开发的过程中也发现了一丢丢的东东,也许以前就知道,只是没有认真的发现. 过程 前几天在开发页面的时候,有个需 ...

  9. 读书计划——javascript dom 编程艺术(一)

    用脑图把基础体系再捋清楚一边.

  10. 【DB】SQLiteHelper

    /// <summary> /// 说明:这是一个针对System.Data.SQLite的数据库常规操作封装的通用类. /// </summary> public class ...