当前位置: 首页 > news >正文

华为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减30dzq = Integer.parseInt(input.split(" ")[1]); // 打折券数量 92折 向下取整wmkq = Integer.parseInt(input.split(" ")[2]); // 无门槛券 减5元 价格>=0int 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;}
}

相关文章:

  • 华为公布《鸿蒙编程语言白皮书》V1.0 版:解读适用场景
  • Ragflow 源码:task_executor.py
  • 数据库(1)-SQL
  • 超详细YOLOv8/11图像菜品分类全程概述:环境、数据准备、训练、验证/预测、onnx部署(c++/python)详解
  • 46- 赎金信
  • VB.NET,C#在线程中修改UI的安全操作
  • Oracle 数据库查询:单表查询
  • Portable Watch:基于STM32的便携智能手表
  • (三十四)深度解析领域特定语言(DSL)第六章——语法分析:第三个案例——优惠规则语法分析器
  • (线性代数最小二乘问题)Normal Equation(正规方程)
  • 跨个体预训练与轻量化Transformer在手势识别中的应用:Bioformer
  • springboot通过独立事务管理器实现资源隔离与精准控制​
  • 2025最新Python 100个常用函数在线体验项目
  • CSP-S 模拟赛一总结(T1、T2)
  • 秋招Day14 - MySQL - SQL优化
  • Java面试复习指南:JVM原理、并发编程与Spring框架
  • JAVA锁机制:对象锁与类锁
  • Windows/Linux系统 Ollama部署deepseek 大模型
  • 区块链:什么是DeFi?
  • C++ 中 QVector 的判断与操作
  • wordpress设置不显示摘要/优化营商环境个人心得体会
  • 一诺建站/手机优化软件
  • 电子元器件商城网站建设/如何做推广呢
  • 个人可以做几个网站/长沙seo霸屏
  • 做360网站中保存的图片存在哪里的/搜索引擎在线
  • 广州建设网站专家/宣传推广方案模板