#include <iostream> #include <iomanip> using namespace std; int main() { double price; cin >> price; double cost = 0.0; // 商品打折,条件语句,分类讨论 if(price < 100) cost = price; if(100 <= price && price < 500) cost = price*0.9; if(500 <= price && price < 2000) cost = price*0.8; if(2000 <= price && price < 5000) cost = price*0.7; if(5000 <= price) cost = price*0.6; cout << setiosflags(ios::fixed) << setprecision(1) << cost << endl; //防止小数点后只有一位且为0时显示为e浮点数,setprecision(n)有n位小数 return 0; }