HDU 1263 水果(map或结构体排序)

来源:互联网 发布:人工智能利大于弊 编辑:程序博客网 时间:2024/05/01 07:10

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263

思路:可以直接结构体快排,也可以用map(强大的STL)


#include <cstdio>#include <cmath>#include <iostream>#include <algorithm>#include <string>#include <cstring>#include <stdlib.h>#include <map>#include <set>#include <stack>#include <queue>#include <iterator>#include <ctype.h>using namespace std;int main(){    int n;    scanf("%d", &n);    while(n--)    {        map <string, map<string, int> > a;        map <string, int> b;        map<string, map<string, int> >:: iterator i;        map<string, int>:: iterator j;        int m;        scanf("%d", &m);        string name, palce;        int num;        while(m--)        {            cin >> name >> palce >> num;            a[palce][name] += num;        }        for(i = a.begin(); i != a.end(); i++)        {            cout << i -> first << endl;            b = i -> second;            for(j = b.begin(); j != b.end(); j++)            {                cout << "   |----" << j -> first << "(" << j -> second << ")" << endl;            }        }        if(n)            cout << endl;    }    return 0;}


0 0
原创粉丝点击