Popular Products_太阁竞赛B

题目2 : Popular Products
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
描述
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  

1111-2222 07/23/2016 888.00  
1111-1111 07/23/2016 999.00  
样例输出

1111-2222


【我的程序】

#include <iostream>
#include <string>
#define maxSize 51
using namespace std;

int main()
{
    int n, m, x, flag[maxSize]={0};
    string id, date, price, temp, refPd[maxSize], ls[maxSize];

    cin>>n >>m;
    for (int i=0;i<m;i++){
        cin>>id >>date >>price;
        refPd[i]=id+price;
    }

    for (int i=0;i<m-1;i++)
        for (int j=0;j<m-1-i;j++)
            if (refPd[j]>refPd[j+1]){ temp=refPd[j]; refPd[j]=refPd[j+1]; refPd[j+1]=temp; }
    for (int i=1;i<m;i++) if (refPd[i]==refPd[i-1]) flag[i]=-1;

    for (int i=1;i<n;i++){
        cin>>x;
        for (int j=0;j<x;j++){
            cin>>id >>date >>price;
            ls[j]=id+price;
        }
        for (int j=0;j<m;j++)
            if (flag[j]>=0) for (int k=0;k<x;k++) if (refPd[j]==ls[k]) { flag[j]++; break; }
    }

    for (int i=0;i<m;i++) if (flag[i]==n-1) cout<<refPd[i].substr(0,9)<<endl;
    return 0;
}


  • 0
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论

打赏作者

薄帷清风

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值