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. Objective-C 学习笔记(Day 3,下)

    ------------------------------------------- 封装概念及其原理 一个Gun类的例子来详细说明这一环节: #import <Foundation/Foun ...

  2. 基于微软EnterpriseLib的框架(一)

    1.框架模型无ORM,重点在数据库建模设计与UI框架设计上 2.多数据库支持(Enterprise Lib 默认仅支持SqlServer和Oracle,需自己扩展才能支持其他数据库,本文已扩展SQLi ...

  3. CSS3的几个标签速记3

    transition:CSS3过渡     css3里很好的一个标签,可以非常方便的完成需要很多JS才能完成的动态效果 例语法:transition:width 2S,height 2S,transf ...

  4. [翻译]AOP编程

    翻译文章链接http://www.codeproject.com/Articles/1080517/Aspect-Oriented-Programming-using-Interceptors-wit ...

  5. Centos7安装并配置mysql5.6完美教程

    Centos7安装并配置mysql5.6完美教程 Centos7将默认数据库mysql替换成了Mariadb,对于我们这些还想使用mysql的开发人员来说并不是一个好消息.然而,网上关于Linux安装 ...

  6. 关于Ionic的安装

    Ionic是一个前端的框架,帮助开发者使用HTML5, CSS3和JavaScript做出原生应用. http://ionicframework.com/getting-started/ 这里介绍了如 ...

  7. About 'atoi'

    在很多地方我们看到的都是:atoi 是一个 C Reference function atoi() convert a string to an integer. This function of s ...

  8. CAF(C++ actor framework)使用随笔(projection 用法)(一)

    最近干活在写毕设,用到了CAF,看了文档,发现了一些小坑,自己摸索写点随笔.(CAF的github网站 https://github.com/actor-framework/actor-framewo ...

  9. Visual Stuido 2015 Community 使用 GitHub 插件

    微软在Visual Studio 2015产品中,深度整合了GitHub,让VS用户更方便的使用GitHub的服务. 新闻链接: Announcing the GitHub Extension for ...

  10. 超强的ACM题目类型总结

    转:初期: 一.基本算法:       (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.       ...