AcWing 660. 零食

阅读 70

2022-01-04

链接
https://www.acwing.com/problem/content/662/

思路
小学计算题

//法1
#include <cstdio>

int main()
{
    int x, y;
    scanf("%d%d", &x, &y);
    
    double price[5] = {4.00, 4.50, 5.00, 2.00, 1.50};
    
    printf("Total: R$ %.2lf",price[x - 1] * y);
    
    return 0;
}
//法2
#include <cstdio>

int main()
{
    int x, y;
    scanf("%d%d", &x, &y);

    double price;
    if (x == 1) price = 4;
    else if (x == 2) price = 4.5;
    else if (x == 3) price = 5;
    else if (x == 4) price = 2;
    else price = 1.5;

    printf("Total: R$ %.2lf\n", price * y);

    return 0;
}

精彩评论(0)

0 0 举报