GESP C++ Level 1 exam questions from September 2025, basic statements (conditional branches, ternary statements) practice, difficulty ★☆☆☆☆.
-
GESP Level 1 Practice Question List
-
GESP Level 1 Exam Question List
-
GESP Level 2 Practice Question List
-
GESP Level 2 Exam Question List
-
GESP Level 3 Practice Question List
-
GESP Level 3 Exam Question List
-
GESP Level 4 Practice Question List
-
GESP Level 4 Exam Question List
-
GESP Level 1-5 Syllabus Analysis
-
Essential Skills for GESP/CSP Programming
luogu-B4409 [GESP202509 Level 1] Store Discounts
Problem Requirements
Problem Description
The store is running a promotional event, offering two discount options. The first option is a discount of yuan off when spending over yuan; the second option is a direct discount of percent, meaning the price becomes . Here, all values are positive integers, and ,.
It is important to note that the first option can only be used once. For example, if the discount is yuan off for spending over yuan, and the selected items total yuan, only yuan can be deducted, and the payment will be yuan.
Xiao Ming has selected items totaling yuan. At checkout, he can only use one discount option. What is the minimum amount Xiao Ming needs to pay?
Input Format
Four lines, four positive integers , as described in the problem statement.
Output Format
One line, a decimal number indicating the minimum amount Xiao Ming needs to pay, rounded to two decimal places.
Input/Output Example #1
Input #1
8
7
9
10
Output #1
3.00
Input/Output Example #2
Input #2
8
7
2
11
Output #2
2.20
Notes/Tips
For all test cases, it is guaranteed that , , .
Problem Analysis
The store offers two mutually exclusive discounts: a discount for spending over and a direct discount of . The goal is to minimize the total price using the best option.
-
Option One (Discount for Spending Over) If , then the payment is ; otherwise, the payment is .
-
Option Two (Direct Discount) The payment is , noting that the result may be a decimal.
-
Select the Optimal Option Compare the payment amounts of the two options and choose the smaller one.
-
Complexity Only constant time operations, time , space .
-
Output Details The result should be rounded to two decimal places. In C++, you can use
<span>printf("%.2f", ans)</span>or<span>cout << fixed << setprecision(2) << ans</span>.
{% include custom/custom-post-content-inner.html %}
Example Code
#include <iostream>
#include <cstdio>
int main() {
int x, y, n, p;
std::cin >> x >> y >> n >> p; // Read four positive integers: spending threshold x, discount amount y, discount n, total price p
int plan_one = p >= x ? p - y : p; // Option one: if spending over x yuan, then deduct y yuan, otherwise pay full price
double plan_two = p / 10.0 * n; // Option two: direct discount, total price multiplied by n/10
double result = plan_one > plan_two ? plan_two : plan_one; // Choose the cheaper option
printf("%.2f", result); // Output the minimum amount to pay, rounded to two decimal places
return 0;
}
For detailed GESP syllabus, exam question explanations, knowledge expansion, and practice lists, see:
【Pinned】【GESP】C++ Certification Learning Resource Compilation
“luogu-” series problems can be evaluated online at Luogu Problem Bank.
“bcqm-” series problems can be evaluated online at Programming Enlightenment Problem Bank.