zoukankan      html  css  js  c++  java
  • Popular Products

    Popular Products

    描述

    Given N lists of customer purchase, your task is to find the products that appear in all of the lists.

    A purchase list consists of several lines. Each line contains 3 parts: the product id (format XXXX-XXXX), the purchase date (format mm/dd/yyyy) and the price (with decimal places). Two product are considered equal if both the product id and the price are equal.  

    输入

    The first line contains an integer N denoting the number of lists. (1 ≤ N ≤ 1000)

    Then follow N blocks. Each block describes one list.  

    The first line of each block contains an integer M denoting the number of products in the list. (1 ≤ M ≤ 50)

    M lines follow. Each line contains the product id, the purchase date and the price.  

    输出

    The products that appear in all of the lists. You should output the product id in increasing order.  

    If two different product share the same id (with different price) you should output the id twice.  

    样例输入
    3  
    2  
    1111-1111 07/23/2016 998.00  
    1111-2222 07/23/2016 888.00  
    2  
    1111-2222 07/23/2016 888.00  
    1111-1111 07/23/2016 998.00  
    2 
    1111-2222 07/23/2016 888.00  
    1111-1111 07/23/2016 999.00  
    样例输出
       1111-2222
    分析:数据可以用map存储,小心模拟,输出有序;
    代码:
    #include <iostream>
    #include <cstdio>
    #include <vector>
    #include <map>
    #include <algorithm>
    #include <string>
    #include <cstring>
    #define rep(i,m,n) for(i=m;i<=n;i++)
    #define pii pair<int,int>
    #define fi first
    #define se second
    #define mp make_pair
    #define pb push_back
    const int maxn=3e4+10;
    using namespace std;
    int n,m;
    map<pair<string,string>,int>p;
    vector<string>ans;
    string a,b,c;
    int main()
    {
        int i,j,k,t;
        scanf("%d",&n);
        rep(i,1,n)
        {
            scanf("%d",&m);
            while(m--)
            {
                cin>>a>>b>>c;
                if(p[mp(a,c)]==i-1)p[mp(a,c)]++;
                if(p[mp(a,c)]==n)ans.pb(a),p[mp(a,c)]=0;
            }
        }
        sort(ans.begin(),ans.end());
        for(string x:ans)cout<<x<<endl;
        //system("pause");
        return 0;
    }
  • 相关阅读:
    对json的爱恨情仇
    Linux操作系统改动PATH的方法
    不好意思啊,我上周到今天不到10天时间,用纯C语言写了一个小站!想拍砖的就赶紧拿出来拍啊
    cmd启动Oracle服务和监听服务
    8.4.1 跨越整个分区的聚合函数
    nginx 代理tcp长连接短连接配置
    Nginx Upstream Keepalive 分析 保持长连接
    Xargs用法详解
    删除除了指定扩展名文件其他全部删除
    LINUX的文件按时间排序
  • 原文地址:https://www.cnblogs.com/dyzll/p/5711436.html
Copyright © 2011-2022 走看看