题解 | #网购#

网购

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

#include <stdio.h>
int checkDate(int monthInput, int dateInput);

int main() {
    // 思路
    // 阶段一: 准备
    // 1. 各种变量(注意变量的类型)
    // 阶段二: 输入
    // 1. scanf()
    // 阶段三: 处理
    // 1. 保证输入日期只有双11和双12
    // 2.
    // - 确定日期
    // - 打几折
    // - 有无优惠券
    // 阶段四: 输出
    double price;
    int month, date;
    int flagCoupon = 1; // 有优惠券为1,无优惠券为0
    int flagDate = 0;   // 1为双11,2为双12,0为默认值

    scanf("%lf %d %d %d", &price, &month, &date, &flagCoupon);
    getchar(); // 吸收缓冲区的换行符,好习惯

    // 判断是否为有效日期哈
    flagDate = checkDate(month, date);
    if (flagDate) {
        if (flagDate == 1 && flagCoupon == 1) {
            price = price * 0.7 - 50;
        } else if (flagDate == 1 && flagCoupon == 0) {
            price = price * 0.7;
        } else if (flagDate == 2 && flagCoupon == 1) {
            price = price * 0.8 - 50;
        } else {
            price = price * 0.8;
        }
        // 如果商品比较便宜,可能会出现用了优惠券价格成负数的情况!
        // 但是这不符合逻辑,因为商家不会倒给买家钱
        price > 0 ? (price = price) : (price = 0);
        printf("%.2lf\n", price);
    }

    getchar();
    return 0;
}

int checkDate(int monthInput, int dateInput) {
    if (monthInput == 11 && dateInput == 11) {
        return 1;
    } else if (monthInput == 12 && dateInput == 12) {
        return 2;
    }
    // 不符合输入要求
    return 0;
}



全部评论

相关推荐

那一天的Java_Java起来:他本来公司就是做这个的,不就是正常的游戏客户端和服务器开发,软硬件联动,有啥恶心不恶心的,提前告诉你就是怕你接受不了,接受不了就没必要再往后走流程浪费时间,虽然这公司是一坨。
点赞 评论 收藏
分享
我面试,她问我有女朋友没
不太迷人的反派_:不过对象,还会结合你老家,意向城市等等,看你是否稳定。哥们,别多想
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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