7-5 电商一 (100 分)

#include<stdio.h>
#include<stdlib.h>
struct book
{
    char name[61];
    int sell;
    int nian;
    int yue;
    int ri;
    int price;
    int score;
};
void pai(struct book a[],int n);
void swap(struct book *a,struct book *b);
int main()
{
    int n;
    scanf("%d",&n);
    struct book *a=malloc(sizeof(struct book)*n);//或者:    struct book a[n];
    for(int i=0;i<n;i++)
    {
        getchar();
        scanf("%s",a[i].name);
        scanf("%d%d%d%d%d%d",&a[i].sell,&a[i].nian,&a[i].yue,&a[i].ri,&a[i].price,&a[i].score);
    }
    pai(a,n);
    for(int i=0;i<n;i++)
    {
        printf("%s %d %d %d %d %d %d\n",a[i].name,a[i].sell,a[i].nian,a[i].yue,a[i].ri,a[i].price,a[i].score);
    }
    return 0;
}
void pai(struct book a[],int n)
{
    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<n-i-1;j++)
        {
            if(a[j].price>a[j+1].price)
            {swap(&a[j],&a[j+1]);
             continue;}
            else if(a[j].price<a[j+1].price)
                continue;
            if(a[j].nian<a[j+1].nian)
            {swap(&a[j],&a[j+1]);
             continue;}
            else if(a[j].nian>a[j+1].nian)
                continue;
            if((a[j].nian==a[j+1].nian)&&(a[j].yue<a[j+1].yue))
            {swap(&a[j],&a[j+1]);
             continue;}
            else if((a[j].nian==a[j+1].nian)&&(a[j].yue>a[j+1].yue))
                continue;
            if((a[j].nian==a[j+1].nian)&&(a[j].yue==a[j+1].yue)&&(a[j].ri<a[j+1].ri))
            {swap(&a[j],&a[j+1]);
             continue;}
            else if((a[j].nian==a[j+1].nian)&&(a[j].yue==a[j+1].yue)&&(a[j].ri>a[j+1].ri))
                continue;
            if(a[j].sell<a[j+1].sell)
            {swap(&a[j],&a[j+1]);
             continue;}
            else if(a[j].sell>a[j+1].sell)
                continue;
            if(a[j].score<a[j+1].score)
            {swap(&a[j],&a[j+1]);
             continue;}
        }
    }
}
void swap(struct book *a,struct book *b)
{
    struct book temp;
    temp=*b;
    *b=*a;
    *a=temp;
}

大家都知道在电商网站上买东西时,网站会根据我们的搜索条件给出非常多的商品。这些商品会以依据某一种排序规则进行排序,依次呈现在我们面前。现在某电商网站关于书籍的排序依据有这么几项,综合、销量、出版时间、价格、用户评分。假设综合排名的规则为:首先看价格,价格低的排名靠前,如果价格相同,则看出版时间,出版的晚的排名靠前,如果这两项都相同则看销量,销量大的靠前,如果前三项均相同,最后看用户评分,用户评分高的排名靠前。

请依据此规则写一段给各个书按综合排名的程序。

输入格式:

第一行为一个整数n(1<n<100),后面是n行书籍的数据,共7列,每列之间以空格分隔。其中第一列为书名(长度小于60且仅包含大写字母和小写字母的字符串),第二列到第七列均为大于等于0的整数,分别代表该书的销量、出版时间的年、月、日、价格和用户评分。

输出格式:

n行,每行输出一本书的信息,与输入时格式一致(测试数据中保证没有排名一样的书籍,且所有整数均可以用int存储)。

输入样例:

3
CPrimerPlus 3000 2013 12 6 60 44
ComputerSystemsAProgrammersPerspective 8000 2015 3 12 156 39
TheCProguammingLanguage 50000 1978 2 22 5 46

输出样例:

TheCProguammingLanguage 50000 1978 2 22 5 46
CPrimerPlus 3000 2013 12 6 60 44
ComputerSystemsAProgrammersPerspective 8000 2015 3 12 156 39
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当然,我可以为您提供一个使用PyTorch进行商销量预测的示例项目。以下是一个简单的示例代码: ```python import torch import torch.nn as nn import torch.optim as optim import numpy as np # 准备数据 train_data = np.array([[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7], [4, 5, 6, 7, 8]], dtype=np.float32) train_labels = np.array([[6], [7], [8], [9]], dtype=np.float32) # 转换为Tensor train_data = torch.from_numpy(train_data) train_labels = torch.from_numpy(train_labels) # 定义模型 class SalesPredictionModel(nn.Module): def __init__(self): super(SalesPredictionModel, self).__init__() self.linear = nn.Linear(5, 1) def forward(self, x): return self.linear(x) model = SalesPredictionModel() # 定义损失函数和优化器 criterion = nn.MSELoss() optimizer = optim.SGD(model.parameters(), lr=0.01) # 训练模型 num_epochs = 1000 for epoch in range(num_epochs): outputs = model(train_data) loss = criterion(outputs, train_labels) optimizer.zero_grad() loss.backward() optimizer.step() if (epoch+1) % 100 == 0: print('Epoch [{}/{}], Loss: {:.4f}'.format(epoch+1, num_epochs, loss.item())) # 使用模型进行预测 test_data = np.array([[5, 6, 7, 8, 9]], dtype=np.float32) test_data = torch.from_numpy(test_data) predicted = model(test_data) print('Predicted sales:', predicted.item()) ``` 这个示例项目使用了一个简单的线性回归模型来预测商销量。你可以根据自己的数据和需求进行相应的修改和扩展。希望对您有帮助!

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

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值