华为OD机考-网上商城优惠活动-模拟(JAVA 2025B卷)

在这里插入图片描述
在这里插入图片描述

import java.util.Scanner;

public class Test3 {
    static int mjq;
    static int dzq;
    static int wmkq;

    static class Group {
        int price;// 打折后价格
        int num;// 优惠券使用熟练
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        mjq = Integer.parseInt(input.split(" ")[0]);// 满减券数量 100减10 200减20
        // 300减30
        dzq = Integer.parseInt(input.split(" ")[1]); // 打折券数量 92折 向下取整
        wmkq = Integer.parseInt(input.split(" ")[2]); // 无门槛券 减5元 价格>=0
        int nums = Integer.parseInt(scanner.nextLine());
        for (int i = 0; i < nums; i++) {
            int price = Integer.parseInt(scanner.nextLine());
            Group g = getMinPrice(price);
            System.out.println(g.price + " " + g.num);
        }

    }

    public static Group getMinPrice(int price) {
        String ways[] = {"MD”, “MY", "DM", "DY", "YM", "YD"};
        Group group = new Group();
        group.price = price;
        group.num = dzq + mjq + wmkq;
        for (String way : ways) {
            Group g = count(way, price);
            if (g.price < group.price) {
                group.price = g.price;
                group.num = g.num;
            } else if (g.price == group.price) {
                if (g.num < group.num) {
                    group.num = g.num;
                }
            }
        }
        return group;
    }

    public static Group count(String way, int price) {
// Map<Integer, Integer> map = new HashMap<Integer, Integer>(); // 价格和数量
        Group group = new Group();
        int mjCount = 0;// 满减券使用数量
        int wmqCount = 0;// 优惠券使用数量
        switch (way) {
            case "MD":
                // 先满减 再打折
                while (mjCount < mjq && price >= 100) {
                    int num = (int) (price / 100) * 10;
                    // System.out.println(price+“_”+num);
                    price -= num;
                    mjCount++;
                }
                // System.out.println(“满减后的价格” + price);
                price = (int) (price * 0.92);
                // System.out.println(“打折后的价格” + price);
                group.price = price;
                group.num = mjCount + 1;
                break;
            case "MY":
                // 先满减 无门槛券
                while (mjCount < mjq && price >= 100) {
                    int num = (int) (price / 100) * 10;
                    // System.out.println(price+“_”+num);
                    price -= num;
                    mjCount++;
                }
                // System.out.println(“满减后的价格” + price);
                while (price > 0 && wmqCount < wmkq) {
                    price -= 5;
                    price = price < 0 ? 0 : price;
                    wmqCount++;
                }
                group.price = price;
                group.num = mjCount + wmqCount;
                // System.out.println(“无门槛后的价格” + price);
                break;
            case "DM":
                // 先打折再满减
                price = (int) (price * 0.92);
                // 先满减 再打折
                // System.out.println(“打折后的价格” + price);
                while (mjCount < mjq && price >= 100) {
                    int num = (int) (price / 100) * 10;
                    // System.out.println(price+“_”+num);
                    price -= num;
                    mjCount++;
                }
                // System.out.println(“满减后的价格” + price);
                group.price = price;
                group.num = mjCount + 1;
                break;
            case "DY":
                // 先打折 再使用无门槛券
                price = (int) (price * 0.92);
                // System.out.println(“打折后的价格” + price);
                while (price > 0 && wmqCount < wmkq) {
                    price -= 5;
                    price = price < 0 ? 0 : price;
                    wmqCount++;
                }
                // System.out.println(“无门槛券后的价格” + price);
                group.price = price;
                group.num = wmqCount + 1;
                break;
            case "YM":
                // 先使用无门槛券 再满减
                while (price > 0 && wmqCount < wmkq) {
                    price -= 5;
                    wmqCount++;
                    price = price < 0 ? 0 : price;
                }
                // System.out.println(“无门槛券后的价格” + price);
                while (mjCount < mjq && price >= 100) {
                    int num = (int) (price / 100) * 10;
                    price -= num;
                    mjCount++;
                }
                // System.out.println(“满减后的价格” + price);
                group.price = price;
                group.num = mjCount + wmqCount;
                break;
            case "YD":
                // 先使用 无门槛券 再使用打折
                while (price > 0 && wmqCount < wmkq) {
                    price -= 5;
                    wmqCount++;
                    price = price < 0 ? 0 : price;
                }
                // System.out.println(“无门槛券后的价格” + price);
                price = (int) (price * 0.92);
                // System.out.println(“打折后的价格” + price);
                group.price = price;
        }
        return group;
    }
}



### 华为OD机考2025B题库及相关资料 华为OD机考2025B的题库和相关资料可以通过以下方式获取或了解。以下是关于2025B的具体内容、备考建议以及相关信息。 #### 1. 题库来源与获取方式 华为OD机考2025B的题库通常由官方提供,但具体题目不会完全公开。考生可以通过以下途径获取相关资料: - **官方在线OJ环境**:华为提供了专门的在线OJ环境用于刷题[^2]。通过私信联系开通OJ环境,可以模拟真实考试场景并练习类似题目。 - **第三方平台**:例如牛客网等平台会整理历年真题及高频考点,供考生参考[^4]。 - **内部分享**:部分参加过考试的考生会在社区中分享经验与题目类型,这些资源可以帮助理解考试模式[^1]。 #### 2. 考试内容概述 2025B主要考察以下几个方面: - **算法设计与实现**:涉及基础数据结构(如数组、链表、栈、队列)和常见算法(如排序、查找、动态规划)[^1]。 - **编程语言基础**:支持多种编程语言(C++、Java、Python、JavaScript等),考生需熟悉所选语言的基本语法与标准库[^4]。 - **实际问题解决能力**:题目通常以实际应用场景为背景,例如数据分类、路径规划等问题[^3]。 #### 3. 备考建议 为了更好地准备2025B,以下是一些具体的备考建议: - **熟悉输入输出方式**:不同语言有各自的输入输出规范。例如,Python使用`input()`和`print()`,C++使用`cin`和`cout`。 - **掌握常见算法模板**:包括但不限于快速排序、二分查找、深度优先搜索(DFS)、广度优先搜索(BFS)等。 - **模拟真实考试环境**:利用在线OJ平台进行模拟练习,确保在规定时间内完成题目[^2]。 #### 4. 示例代码 以下是一个简单的示例代码,展示如何处理输入输出并解决问题: ```python # 数据分类问题示例 def data_classification(data, threshold): result = [] for item in data: if item > threshold: result.append(item) return result # 输入处理 if __name__ == "__main__": n = int(input()) # 数据数量 data = list(map(int, input().split())) # 数据列表 threshold = int(input()) # 阈值 output = data_classification(data, threshold) print(len(output)) # 输出符合条件的数据数量 ``` 此代码展示了如何读取输入数据并根据条件筛选结果[^4]。 ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值