题解 | #网购#

网购

http://www.nowcoder.com/practice/5d7dfd405e5f4e4fbfdff6862c46b751

import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()) {
			double oldPrice = Double.parseDouble(scan.next());
            int month = Integer.parseInt(scan.next());
            int day = Integer.parseInt(scan.next());
            int isBargar = Integer.parseInt(scan.next());
            double newPrice = oldPrice;
            
            if(month == 11 && day == 11 || month == 12 && day == 12) {//判断日期是否为双11或双12
                double discount = month == 11 ? 0.7 : 0.8;//双11和双12折扣不同
                newPrice *= discount; //打完折后的价格
                if(isBargar == 1) {//如果有优惠券,还需要再减去50
                    newPrice -= 50;
                }
            }
            System.out.printf("%.2f", Math.max(newPrice, 0));//注意,最终价格不可能低于
        }
    }
}
全部评论

相关推荐

真的很糟糕:不一定是你的问题,当然你也可以做的更好一些,继续投相信自己一定会有的
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务