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. MS SQLService中的*= 及 =*

    今天看到数据库中的存储过程中,有*= ,于是百度了一下,原来这个SQL2000以前的左连接,以后的版本中开启兼容也是可以用的. 于是拿出来在系统中的表中测试了一下果然如此 例: 有用户表D_user及 ...

  2. windows server 2003 负载平衡的详细设置步骤(转载)

    声明:本文为转载. 当把一台服务器(包括Web服务器.FTP服务器或者流媒体服务器等等)放入网络中之后,随着客户端数量的不断增加,人们往往需要功能更强大.处理速度更快的服务器.为了解决这个问题,如果将 ...

  3. Java实战之04JavaWeb-04JSP、EL表达式、JSTL标签库

    一.jsp部分 只要是与页面显示相关的都是重点 1.jsp的脚本 <%java代码%>:被翻译到service方法内部,局部变量,局部的功能 <%=表达式或变量%>:翻译成se ...

  4. Windows和Linux下查看Apache、MySQL、PHP版本

    # Windows查看Apache版本: 使用命令:httpd -v # Linux查看Apache版本: 使用命令:apachectl -v # Windows查看MySQL版本: 使用命令:mys ...

  5. socket通信_笔记

    (socket通信) 客户端与服务器端通信问题: 我们首先要了解一个概念性的词汇:Socket socket的英文原义是“孔”或“插座”.作为进程通信机制,取后一种意思.通常也称作“套接字”,用于描述 ...

  6. 支付宝api教程,支付宝根据交易号自动充值

    最近公司要用php做一个网站支付宝自动充值的功能,具体就是客户把钱直接转到公司的支付宝账号里,然后在我们网站上填写上交易号,我们网站程序自动获取交易信息,自动给网站的账户充值. 我的具体想法就是利用支 ...

  7. 让c像python一样可以在命令行写代码并且编译

    在你亲爱的.bashrc/.zshrc中添加 ###C###go_libs="-lm"go_flags="-g -Wall -include allheads.h -O3 ...

  8. mysql 之权限介绍

    转自:http://tech.it168.com/a2010/0114/837/000000837456_all.shtml 一.MySQL授权表概述首先从全局开始,如果全局的是允许的,即在 user ...

  9. 算法之插入排序(inertionSort)

    插入排序的基本操作就是将一个数据插入到已经排好序的有序数据中,从而得到一个新的.个数加一的有序数据,适用于少量数据的排序,时间复杂度为O(n^2). 插入排序属于稳定排序. 插入排序不需要构造新的数据 ...

  10. JAVA 修改 JSESSIONID

    @Action("sidTest") public void sidTest() { HttpSession session = request.getSession(); Str ...