Analysis of C++ Level 1 T1 Mathematics and Programming Application Problems for the National Unified Examination on September 27, 2025

Store Discounts

Problem Description

The store is running a promotional event, offering two discount options. The first option is to reduce the price by y yuan when spending at least x yuan; the second option is a direct discount of n percent, meaning the price becomes n/10 of the original. Here, x, y, and n are all positive integers, and 1≤y<x, 1≤n<10.

It is important to note that the first option can only be used once. For example, if the discount is to spend 10 yuan and get 3 yuan off, and the total price of selected items is 33 yuan, only 3 yuan can be deducted, resulting in a payment of 30 yuan.

Xiao Ming selected items totaling p yuan in the store and can only use one discount option at checkout. What is the minimum amount Xiao Ming needs to pay?

Input Format

Four lines, each containing a positive integer x, y, n, p, as described in the problem.

Output FormatOne line, a decimal number indicating the minimum amount Xiao Ming needs to pay, rounded to two decimal places.Sample Input 187910Sample Output 13.00Sample Input 287211Sample Output 22.20Analysis and Solution Approach:The problem requires that Xiao Ming has two discount options to choose from, but can only select one. The first option is a discount of y yuan for spending x yuan, and the second option is a discount of n percent (i.e., multiplied by n/10).

We need to calculate the payment amount for both options and take the minimum value, rounding to two decimal places. Note: The first option can only be used once, so if the total price p is greater than or equal to x, then y yuan can be deducted; otherwise, no deduction can be applied.

The second option is a direct discount of n percent, meaning the payment is p * n / 10.0. Input: Four positive integers x, y, n, p, each on a new line. Output: The minimum payment amount rounded to two decimal places. Based on the samples:

Sample 1: x=8, y=7, n=9, p=10

Option 1: Spend 8 yuan and get 7 yuan off, since 10>=8, the payment is 10-7=3 yuan.

Option 2: 10 yuan with a 9 percent discount, the payment is 10*9/10=9 yuan.

The minimum value is 3.00. Sample 2: x=8, y=7, n=2, p=11

Option 1: Spend 8 yuan and get 7 yuan off, since 11>=8, the payment is 11-7=4 yuan.

Option 2: 11 yuan with a 2 percent discount, the payment is 11*2/10=2.2 yuan.

The minimum value is 2.20. Therefore, we calculate the results for both options and take the minimum value. Note: Since the second option may result in a decimal, we need to use a floating-point number to store the result. Steps:

1. Read the four integers x, y, n, p.

2. Calculate the payment amount for option 1: If p >= x, then the payment is p-y; otherwise, the payment is p.

3. Calculate the payment amount for option 2: p * n / 10.0.

4. Take the minimum of the two payment amounts and output it rounded to two decimal places.

Note: Since the problem requires rounding to two decimal places, we can use printf for output or use setprecision from iomanip.

Implementation Steps:

1. Input handling: Read the four integers x (minimum spending), y (discount amount), n (discount coefficient), p (total price of goods).

2. Calculate option one (minimum spending): If the total price p ≥ minimum spending x, then apply the discount: payment = p – y; otherwise, no discount: payment = p.

3. Calculate option two (discount): Directly calculate the discounted price: payment = p × n ÷ 10.

4. Compare and choose: Use the min() function to select the lower payment amount from the two options.

5. Output the result: Use fixed and setprecision(2) to ensure the output is rounded to two decimal places.

Sample Validation:

• Sample 1: x=8, y=7, n=9, p=10

Option 1: 10≥8, payment is 10-7=3 yuan.

Option 2: 10×9÷10=9 yuan, minimum value: 3.00 ✓

• Sample 2: x=8, y=7, n=2, p=11

Option 1: 11≥8, payment is 11-7=4 yuan.

Option 2: 11×2÷10=2.2 yuan.

Minimum value: 2.20 ✓

This solution is concise and efficient, with a time complexity of O(1), capable of correctly handling various edge cases.

// Import input-output stream#include <iostream>// Import function library#include <iomanip>// Namespace using namespace std;int main(){/* x represents the minimum spending amount y represents the discount amount n represents the discount p represents the total price of goods */ // Declare variables int x,y,n,p; // Input variables cin >> x >> y >> n >> p; // First discount calculation plan, minimum spending double plan1; if(p >= x){ // Actual payment amount = total price - discount plan1 = p - y; }else{ // Does not meet minimum spending requirement // Actual payment amount = total price plan1 = p; } // Second discount calculation plan // Actual payment amount = total price * discount (n/10) double plan2 = p * n / 10.00; // Choose the lower price from the two discount options double min_price = min(plan1,plan2); // Round to two decimal places cout << fixed << setprecision(2) << min_price << endl; return 0; } 

Leave a Comment