水果

夏天来了好开心啊,呵呵,好多好多水果
Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容易掌握所有水果的销售情况了.
Input
第一行正整数N(0

#include<cstdio>
#include<map>
#include<iostream>
#include<string>

using namespace std;

int main()
{
    int t; cin >> t;
    while(t --)
    {
        map <string, map <string, int> >ss; // 定义二维map
        string f, p;
        int n; cin >> n;
        map< string, map <string, int> >  :: iterator it1; //  外迭代器
        map< string, int> :: iterator it2; // 内迭代器
        while ( n--)
        {
            int m; // 水果数量
            cin >> f >> p >> m;
            ss[p][f] += m;     //这里就是map的功能,能去重并且把键相等的值相加 
        } 
        for (it1 = ss.begin(); it1 != ss.end(); it1 ++)
        {
            cout << it1 -> first << endl;
            for (it2 = it1 -> second.begin(); it2 != it1 -> second.end(); it2 ++)
                cout << "   |----" << it2 -> first << "(" << it2 -> second << ")" << endl;
        }
        if(t != 0)
            puts("");
    }
    return 0;
 } 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值