夏天来了~~好开心啊,呵呵,好多好多水果~~
Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容易掌握所有水果的销售情况了.
Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容易掌握所有水果的销售情况了.
每组测试数据的第一行是一个整数M(0<M<=100),表示工有M次成功的交易.其后有M行数据,每行表示一次交易,由水果名称(小写字母组成,长度不超过80),水果产地(小写字母组成,长度不超过80)和交易的水果数目(正整数,不超过100)组成.
两组测试数据之间有一个空行.最后一组测试数据之后没有空行.
1 5 apple shandong 3 pineapple guangdong 1 sugarcane guangdong 1 pineapple guangdong 3 pineapple guangdong 1
guangdong |----pineapple(5) |----sugarcane(1) shandong |----apple(3)
map的嵌套,我也是才晓得有嵌套的用法,这下如果有题需要很多keyvalue的时候就好设置了。
代码如下:
//
// main.cpp
// C - stl 的 map
//
// Created by 徐智豪 on 2017/3/29.
// Copyright © 2017年 徐智豪. All rights reserved.
//
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(int argc, const char * argv[]) {
int N;
cin>>N;
while(N--)
{
map<string,map<string,int>> conclusion;
int M;
cin>>M;
string location,fruit;
int sum=0;
while(M--)
{
cin>>fruit>>location>>sum;
conclusion[location][fruit]+=sum;
}
map<string,map<string,int>>::iterator p;
map<string,int>::iterator q;
for(p=conclusion.begin();p!=conclusion.end();p++)
{
cout<<p->first<<endl;
for(q=p->second.begin();q!=p->second.end();q++)
{
cout<<" |----"<<q->first<<"("<<q->second<<")"<<endl;
}
}
if(N)cout<<endl;
}
return 0;
}