zoukankan      html  css  js  c++  java
  • 实验7:Problem G: STL——水果店

    Description

    小明经营着一个不大的水果店.现在他想要一份水果销售情况的明细表,这样就可以很容易掌握所有水果的销售情况了.

    Input

    输入包含多组数据.每组测试数据的第一行是一个整数M(0<M<=100),表示有M次成功的交易.其后有M行数据,每行表示一次交易,由水果名称(长度不超过80)和交易的水果数目(正整数,不超过100)组成.

    Output

    对于每一组测试数据,请你输出一份排版格式正确(请分析样本输出)的水果销售情况明细表.这份明细表包括所有水果的名称和其销售总数的信息.按照水果名称排序。格式见样例!

    Sample Input

    3 apple 3 sugarcane 1 pineapple 3

    Sample Output

    apple:3 pineapple:3 sugarcane:1

    HINT

     用STL的map容易实现

    Append Code

    #include<iostream>
    #include<map>
    #include<string>
    #include<algorithm>
    using namespace std;
    int main() {
        int n,a;
        string b;
        while(cin>>n){
            map<string,int> s;
            while(n--){
                cin>>b>>a;
                s[b]+=a;
            }
            map<string,int>::iterator p;
            for(p=s.begin();p!=s.end();p++)
                cout<<p->first<<":"<<p->second<<endl;
        }
        return 0;
    }
    向代码最深处出发~!
  • 相关阅读:
    2016.7.22.noip2012D2
    2016.7.21.noip2014D2
    LIS最长上升子序列O(n^2)与O(nlogn)的算法
    vijos1910解方程
    vijos1909寻找道路
    viojs1908无线网路发射器选址
    P1907飞扬的小鸟
    P1906联合权值
    P1905生活大爆炸版 石头剪刀布
    poj1274(匈牙利算法)
  • 原文地址:https://www.cnblogs.com/auto1945837845/p/5408917.html
Copyright © 2011-2022 走看看