zoukankan      html  css  js  c++  java
  • hdu 1263 水果(map)

    题目链接:https://vjudge.net/problem/HDU-1263

      map嵌套就行了

    #include<set>
    #include<map>
    #include<stack>
    #include<queue>
    #include<cmath>
    #include<cstdio>
    #include<cctype>
    #include<string>
    #include<vector>
    #include<climits>
    #include<cstring>
    #include<cstdlib>
    #include<iostream>
    #include<algorithm>
    #define max(a, b) (a > b ? a : b)
    #define min(a, b) (a < b ? a : b)
    #define mst(a) memset(a, 0, sizeof(a)*maxn)
    #define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> P;
    const double eps = 1e-7;
    const int INF = 0x3f3f3f3f;
    const ll ll_INF = 233333333333333;
    string plc;
    int main(void) {
        //std::ios::sync_with_stdio(false);
        map<string, map<string, int> > a; 
        //先定义一个水果名字->水果数量的映射,再定义一个产地->水果信息的映射
        int t;
        scanf("%d", &t);
        while(t--) {
            int n;
            scanf("%d", &n);
            string place, fruname;
            int cnt;
            for (int i = 0; i<n; ++i) {
                cin >> fruname >> place >> cnt;
                a[place][fruname] += cnt; //双重映射的一种访问方式
            }
            map<string, map<string, int> >::iterator it;
            for (it = a.begin(); it != a.end(); ++it) {
                cout << it->first << endl;
                map<string, int>::iterator it2;
                for (it2 = it->second.begin(); it2 != it->second.end(); ++it2)
                    cout << "   |----" << it2->first << '(' << it2->second << ')' << endl;
            }
            a.clear();
            if (t)
                cout << endl;
        }
        return 0;
    }   
    

      

  • 相关阅读:
    HTML总结
    js五角星评分特效
    正则表达式
    C#文件路径的写法
    vs2010发布网站
    INI文件阅读器
    .net读取xml文件中文乱码问题解决办法
    js利用定时器动态改变层大小
    c#中ref和out的用法
    分享一篇关于C#对文件操作的日志,方法很全
  • 原文地址:https://www.cnblogs.com/shuitiangong/p/12210419.html
Copyright © 2011-2022 走看看