Popular Products_太阁竞赛B

本题旨在找出一组顾客购买清单中所有出现的商品。每个购买记录包括产品ID、购买日期及价格,相同ID但不同价格的商品被视为不同。需要处理多个购买清单,并输出所有清单中共有的商品ID。
题目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;
}


# 自动售货机市场运营数据分析 - 优化建议部分 ## 代码概述 该代码片段旨在基于自动售货机销售数据分析结果,生成具有实际意义的运营优化建议。主要包含以下几个方面: - 识别销售额低于平均的自动售货机 - 确定各地点最畅销的产品类别 - 分析各地点最受欢迎的支付方式 - 生成优化建议报告 ## 代码解析 ```python # 5 生成优化建议 report = "根据分析结果,提出如下优化建议:\n" # 找出销售额低于平均的自动售货机 low_sales_machines = total_sales[total_sales['Total_Sales'] < total_sales['Total_Sales'].mean()]['Machine'].tolist() if low_sales_machines: report += f"- 对于销售额较低的自动售货机 {low_sales_machines},建议重新评估其位置或调整产品组合。\n" # 找出各地点最畅销的产品类别 popular_products_by_location = preference.idxmax(axis=1).to_dict() for location, category in popular_products_by_location.items(): report += f"- 在 {location} 地区,用户更喜欢 {category} 类产品,可以增加这些产品的库存。\n" # 找出各地点最受欢迎的支付方式 payment_preference_numeric = payment_preference.select_dtypes(include='number') preferred_payment_methods = payment_preference_numeric.idxmax(axis=1).to_dict() for location, method in preferred_payment_methods.items(): report += f"- 在 {location} 地区,用户更倾向于使用 {method} 支付,建议优化该地区的支付设备配置。\n" print(report) ``` 1. 首先定义了一个空的优化建议报告字符串 2. 然后找出销售额低于平均的自动售货机,并添加相应的优化建议 3. 接着分析各地点最畅销的产品类别,并将结果添加到报告中 4. 再分析各地点最受欢迎的支付方式,并将建议添加到报告中 5. 最后打印完整的优化建议报告 ## 知识点详解 1. **数据筛选与条件判断** 通过条件表达式筛选满足条件的数据,如筛选销售额低于平均值的自动售货机。 2. **数据透视与聚合分析** 使用idxmax()等函数找出最大值位置,进行各地点偏好分析。 3. **数据类型选择** 使用select_dtypes()选择特定数据类型,以便进行后续分析,避免非数值型数据干扰。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值