Files
exercises/cs101/dh_20260917_02_subway.cpp
T
2026-09-25 20:20:01 +08:00

35 lines
824 B
C++

#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
double get_price(int spent_money, int distance) {
double price = 0;
if (distance <= 6) {
price = 3;
} else {
price = 4;
}
distance -= 12;
if (distance > 0 && distance <= 32 - 12) { price += ceil(distance / 10.0); }
distance -= 32 - 12;
if (distance > 0) { price += ceil(distance / 20.0); }
if (spent_money >= 400) { return price; }
if (spent_money >= 150) { return price * 0.5; }
if (spent_money >= 100) { return price * 0.8; }
return price;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int spent_money, distance;
cin >> spent_money >> distance;
cout << fixed << setprecision(2) << get_price(spent_money, distance) << endl;
return 0;
}