水果店

题目
问题描述

蒜头君经营着一个不大的水果店。他认为生存之道就是经营最受顾客欢迎的水果。现在他想要一份水果销售情况的明细表,这样就可以很容易掌握所有水果的销售情况了。蒜头君告诉你每一笔销售记录的水果名称,产地和销售的数量,请你帮他生成明细表。
输入格式
第一行是一个整数 N(0 < N≤1000),表示工有N 次成功的交易。其后有 N 行数据,每行表示一次交易,由水果名称(小写字母组成,长度不超过 100),水果产地(小写字母组成,长度不超过 100)和交易的水果数目(正整数,不超过 1000)组成.
输出格式
请你输出一份排版格式正确(请分析样本输出)的水果销售情况明细表。这份明细表包括所有水果的产地、名称和销售数目的信息。水果先按产地分类,产地按字母顺序排列;同一产地的水果按照名称排序,名称按字母顺序排序。
样例输入
5
apple shandong 3
pineapple guangdong 1
sugarcane guangdong 1
pineapple guangdong 3
pineapple guangdong 1
样例输出
guangdong
|—-pineapple(5)
|—-sugarcane(1)
shandong
|—-apple(3)

代码


#include <iostream>
#include <cstdio>
#include <set>
#include <map>
using namespace std;
int main()
{   set<string>cds;
    set<string>nams;
    map<string,map<string,int> >dat;
    int n;
    cin>>n;
    while(n--)
    {   int xl;
        string cd,nam;
        cin>>nam>>cd>>xl;
        cds.insert(cd);
        nams.insert(nam);
        if(!dat.count(cd) )dat[cd][nam]=0;
        else if(!dat[cd].count(nam))dat[cd][nam]=0;
        dat[cd][nam] +=xl;
    }
    for (set<string>::iterator it=cds.begin();it !=cds.end();++it)
    {string a=*it;
    cout<<a;
        for (set<string>::iterator itt=nams.begin();itt !=nams.end();++itt)
        {
        if(dat[a].count(*itt) )cout<<"\n"<<"   |----"<<*itt<<"("<<dat[a][*itt]<<")";
        }
    cout<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值