I believe a careful planner like you must know that each convenience store offers different discounts on perishable goods at different times.
The following is information related to promotions:
Store Name | Store ID | Discount Time(s) | Discount |
---|---|---|---|
LIME | 0 | 18:00 – 00:00 | 30% Off |
Your House | 1 | 10:00 – 17:00 / 17:00 – 00:00 | 30% Off |
-4 | 2 | 10:00 – 17:00 / 20:00 – 00:00 | 35% Off |
No Prob | 3 | 16:30 – 22:30 | 40% Off |
Given N transaction records,
Each transaction record is represented as {id, h, m, a}, where:
id: convenience store ID
h: purchase hour
m: purchase minute
a: original price of the purchased item
You can assume that as long as it is within the promotion period of the convenience store, only discounted perishable items will be purchased.
Please help calculate the total actual consumption amount after the discount for N transaction records. For each transaction, round down the decimal point.
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
The first line contains a positive integer N, indicating the number of transaction details. 1 ≤ N ≤ 1000 Then, there are N lines, each containing four integers id, h, m, a. They represent the convenience store ID, the purchase hour, the purchase minute, and the original price of the purchased item, respectively. 0 ≤ id ≤ 3 0 ≤ h ≤ 23 0 ≤ m ≤ 59 0 ≤ a ≤ 1000 | The total actual consumption amount after the discount should be calculated. For each transaction, round down the decimal point. |
4 0 19 30 100 1 19 30 100 2 19 30 100 3 19 30 100 | 300 |
2 0 0 0 100 3 16 0 100 | 170 |
Thought Process
Convert the current time to the unit of "minutes" and also convert the discount period into "minutes" when using conditional statements.
Sample Code-ZeroJudge K570: Store Discounts
#include <iostream>
using namespace std;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int N, ans = 0;
cin >> N;
for (int i = 0; i<N; i++) {
int id, h, m, a;
cin >> id >> h >> m >> a;
int min = m + (h*60);
if (id == 0) {
if (min >= 1080 || min == 0) ans += a*0.7;
else ans += a;
continue;
}
if (id == 1) {
if (min >= 600 || min == 0) ans += a*0.7;
else ans += a;
continue;
}
if (id == 2) {
if ((min >= 600 && min <= 1020) || min >= 1200 || min == 0) ans += a*.65;
else ans += a;
continue;
}
if (min >= 990 && min <= 1350) ans += a*.6;
else ans += a;
}
cout << ans << "\n";
}
//ZeroJudge K570
//Dr. SeanXD