#include <stdio.h> int main() { float weight = 0; char decision = 0; int price = 0; scanf("%f %c", &weight, &decision);//输入 if (weight <= 1.0)//快递重量在1kg内的情况 { price = 20; if (decision == 'y') { price += 5; } else { price -= 0; } } if (weight > 1.0)//快递重量超过1kg的情况 { int overprice = 0;//超过1kg部分重量的价格 price = 20; weight -= 1.0; float weight2 = weight;//用于下式代值运算 if (decision == 'y') { price += 5; } else { price -= 0; } weight = weight - (int) weight;//判定是否还有小数 if (weight == 0) { overprice = (int) weight2; price += overprice; } else { overprice = (int) weight2 + 1; price += overprice; } } printf("%d\n", price); return 0; }