首页 > 试题广场 >

网购

[编程题]网购
  • 热度指数:71356 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
KiKi非常喜欢网购,在一家店铺他看中了一件衣服,他了解到,如果今天是“双11”(11月11日)则这件衣服打7折,“双12” (12月12日)则这件衣服打8折,如果有优惠券可以额外减50元(优惠券只能在双11或双12使用),求KiKi最终所花的钱数。

数据范围:衣服价格满足

输入描述:
一行,四个数字,第一个数表示小明看中的衣服价格,第二和第三个整数分别表示当天的月份、当天的日期、第四个整数表示是否有优惠券(有优惠券用1表示,无优惠券用0表示)。
注:输入日期保证只有“双11”和“双12”。


输出描述:
一行,小明实际花的钱数(保留两位小数)。(提示:不要指望商家倒找你钱)
示例1

输入

1000.0 11 11 1

输出

650.00
示例2

输入

999.8 12 12 0

输出

799.84
示例3

输入

66.6 11 11 1

输出

0.00
#include<stdio.h>
int main()
{
    float price,sum;
    int month,day,flag;
    scanf("%f%d%d%d",&price,&month,&day,&flag);
    if(month==11&&day==11)
    {
        sum=0.7*price;
        if(flag==1)
        {
            if(sum>=50)
                sum-=50;
            else 
                sum=0;
        }
    }
    else if(month==12&&day==12)
    {
        sum=0.8*price;
        if(flag==1)
        {
            if(sum>=50)
                sum-=50;
            else
                sum=0;
        }
    }
    else 
    {
        sum=price;
    }
    printf("%.2f",sum);
    return 0;
}


发表于 2021-02-25 20:29:27 回复(2)

#include<stdio.h>
int main()
{
    double y,jg;int month,day,flag=0;
    scanf("%lf%d%d%d",&y,&month,&day,&flag);
    if(month==11&&day==11)
    {
        jg=y*0.7;
        if(flag==1)
            jg-=50;
            
    } 
    if(month==12&&day==12)
    {
        jg=y*0.8;
        if(flag==1)
            jg-=50;
    }
    if(jg<0)
        printf("0.00");
    else
        printf("%.2f",jg);
}

发表于 2022-01-04 19:11:47 回复(0)
#include<stdio.h>
int main()
{
    int month,day,quan;
    float money,c,d;
    scanf("%f %d %d %d",&money,&month,&day,&quan);
    month==day;
    d=money*0.7-50;
    c=money*0.8-50;
    switch(month)
   {
case 11:if(quan)
        {
            if(d>=0)
            {
               printf("%.2f",money*0.7-50);break;
            }
            else
               printf("0.00");break;
        }
            else
               printf("%.2f",money*0.7);break;
case 12:if(quan)
         {
            if(c>=0)
            {
               printf("%.2f",money*0.8-50);break;
            }
           else
               printf("0.00");break;
         }
           else
               printf("%.2f",money*0.8);break;
   }
   return 0;
     }

发表于 2021-12-19 22:52:04 回复(0)
#include<iostream>
#include<iomanip>
using namespace std;

int main(void)
{
	float a, b, c, d;
	while (cin >> a >> b >> c >> d)
	{
		if (b == 11 && c == 11)
		{
			a = 0.7 * a;
		}
		else if (b == 12 && c == 12)
		{
			a = 0.8 * a;
		}

		if (d == 1)
		{
			a -= 50;
			if (a < 0)
			{
				a = 0;
			}
		}

		cout << fixed << setprecision(2) << a << endl;
	}

	return 0;
}

发表于 2021-11-05 21:35:08 回复(0)
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        double price = in.nextDouble();
        int month = in.nextInt();
        int day = in.nextInt();
        int coupon = in.nextInt();
        if(month==day&&month==12){
            price = price*0.8;
        }
        if(month==day&&month==11){
            price = price*0.7;
        }
        if(coupon==1){
            price = price - 50;
        }
        System.out.printf("%.2f",price>0?price:0.0);
    }
}

发表于 2021-09-03 10:17:56 回复(0)
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str[] = sc.nextLine().split(" ");
        if(str[1].equals("11")&&str[2].equals("11")){
            double money = Double.parseDouble(str[0]);
            double realmoney = money*0.7;
            if(str[3].equals("1")){
                realmoney = realmoney - 50;
                if(realmoney<0){
                    realmoney = 0;
                }
            }
            System.out.printf("%.2f",realmoney);
        }
        else if(str[1].equals("12")&&str[2].equals("12")){
            double money = Double.parseDouble(str[0]);
            double realmoney = money*0.8;
            if(str[3].equals("1")){
                realmoney = realmoney - 50;
                if(realmoney<0){
                    realmoney = 0;
                }
            }
            System.out.printf("%.2f",realmoney);
        }
        else{
            double money = Double.parseDouble(str[0]);
            double realmoney = money;
            System.out.printf("%.2f",realmoney);
        }
    }
}

发表于 2021-08-10 15:58:02 回复(0)
#include<stdio.h>
int main()
{
    float m;
    int x,y,z;
    scanf("%f%d%d%d",&m,&x,&y,&z);
    if(x==11&&y==11)
        m=m*0.7;
    else if(x==12&&y==12)
        m=m*0.8;
    if(z==1)
        m=m-50;
    if(m<0)
        printf("0.00");//商家不会倒找钱
    else
        printf("%.2f",m);
    return 0;
}

发表于 2021-07-07 15:28:04 回复(0)
#include <stdio.h>
int main()
{
    float price;
    int month,day,cou;
    scanf("%f %d %d %d",&price,&month,&day,&cou);
    while(cou==1) //有优惠券
    {
        if(month==11&&day==11) //11月11日
        {
            if(price*0.7<=50) //判断打折后还够不够减去优惠券
            {
                printf("0.00");
            }
            else
            {
                printf("%.2f",price*0.7-50);
            }
        }
        else if(month==12&&day==12)
        {
            if(price*0.8<=50)
            {
            printf("0.00");
            }
            else
            {
            printf("%.2f",price*0.8-50);
            }
        }
        break;
    }
    while(cou==0)//无优惠券
    {
        if(month==11&&day==11)
        {
            printf("%.2f",price*0.7);
        }
        else if(month==12&&day==12)
        {
            printf("%.2f",price*0.8);
        }
       break;
    }
    return 0;
}
发表于 2021-05-11 23:43:48 回复(0)
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        double price=input.nextDouble();
        int mm=input.nextInt();
        int dd=input.nextInt();
        int flag=input.nextInt();
        if(mm==11&&dd==11) price*=0.7;
        else if(mm==12&&dd==12) price*=0.8;
        if(flag==1)price-=50;
        price=price<0?0:price;
        System.out.println(String.format("%.2f",price));
    }
} 
发表于 2020-10-29 19:18:01 回复(0)
#include <iostream>
int main()
{
    float tr;
    int month , date , yn;
    scanf("%f %d %d %d",&tr, &month, &date, &yn);
    float num;
    if(month == 11 && date == 11)
    {
        if(yn == 1)
            num = tr * 0.7 - 50;
        else
            num = tr * 0.7;
    }
    if(month == 12 && date == 12)
    {
       if(yn == 1)
          num = tr * 0.8 - 50;
       else
          num = tr * 0.8;
    }
    if(num <= 0.0)
        printf("0.00");
    else
        printf("%.2f",num);
    return 0;
}

发表于 2020-10-14 17:30:24 回复(0)
#include <stdio.h>

int main()
{
    float price, disc;
    int mon, day, discount;
    scanf("%f%d%d%d", &price, &mon, &day, &discount);
    if(mon == 11 && day == 11)
        disc = 0.7;
    else if(mon == 12 && day == 12)
        disc = 0.8;
    else
        disc = 1;
    price *= disc;
    if(discount)
        price -= 50;
    if(price < 0)
        price = 0;
    printf("%.2f\n", price);
}

编辑于 2020-04-06 12:19:53 回复(0)
#include<stdio.h>
int main() {
    double price;
    int month,date,have;
    scanf("%lf%d%d%d",&price,&month,&date,&have);
    int two11 = month==11&&date==11,two12 =month==12&&date==12;
    if(two11) price*=0.7;
    if(two12) price*=0.8;
    if(have&&(two11||two12)) price-=50;
    printf("%.2lf",price<0?0:price);
}
11行,应该算比较简洁了
发表于 2021-09-01 00:06:14 回复(3)
a = list(map(float,input().split()))
if int(a[1]) == 11:
    p = a[0]*0.7 - 50*a[3]
else:
     p = a[0]*0.8 - 50*a[3]
print("{:.2f}".format(p if p>0 else 0))

发表于 2024-02-04 13:07:53 回复(0)
#include<iostream>
#include<iomanip>
using namespace std;

int main()
{
    int month,day,coupon;
    float price;
    cin>>price>>month>>day>>coupon;
    float discount;
    bool cou_flag=false;
    if(month==11&&day==11)
    {
        discount=0.7;
        cou_flag=true;
    }
    else if(month==12&&day==12)
    {
        discount=0.8;
        cou_flag=true;
    }
    else
        discount=1;
    price=price*discount;
    if(cou_flag&&coupon==1)
    {
        if(price>50)
            cout<<fixed<<setprecision(2)<<price-50<<endl;
        else
            cout<<fixed<<setprecision(2)<<0.00<<endl;
    }
    else
        cout<<fixed<<setprecision(2)<<price<<endl;
    return 0;
}

发表于 2020-07-26 15:41:25 回复(0)
int main()
{
    double a;
    int b,c,d;
    scanf("%lf%d%d%d",&a,&b,&c,&d);
    if(b==11&&c==11)
    {
        if(d==1)
        {
            if(0.7*a-50<=0)
            {
                printf("0.00");
            }
            else 
            {
                printf("%.2lf",0.7*a-50);
            }
        }
        else
        { 
        printf("%.2lf",0.7*a);
        }
    }
    if(b==12&&c==12)
    {
        if(d==1)
        {
            if(0.8*a-50<=0)
            {
                printf("0.00");
            }
            else 
            {
                printf("%.2lf",0.8*a-50);
            }
        }
        else 
        {
            printf("%.2lf",0.8*a);
        }
    }
}

发表于 2024-11-10 16:17:48 回复(0)
#include<stdio.h>

double count_66(double num1,int month,int day,int discount){
    if(month==11&&day==11){
        num1=(num1*0.7)-(50*discount);
    }
    else if(month==12&&day==12){
        num1=(num1*0.8)-(50*discount);
    }
    return num1;
}

int main() {
    double num1,res;int month,day,discount;
    scanf("%lf %d %d %d",&num1,&month,&day,&discount);
    res=count_66(num1,month,day,discount);
    printf("%.2lf",(res>0.00?res:0.00));
        return 0;
    }


发表于 2024-05-31 10:31:20 回复(0)
#include <stdio.h>

int main()
{
    double arr[4] = { 0 };
    int i = 0;
    for(i = 0; i < 4; i++)
    {
        scanf("%lf ",&arr[i]);
    }

    double money = 0;

    money = arr[0];
    if(arr[1] == 11 &&arr[2] == 11)
    {
        money = arr[0]*0.7-arr[3]*50; 
    }
    if(arr[1] == 12 && arr[2] == 12)
    {
        money = arr[0]*0.8 - arr[3] *50;
    }


    if(money > 0)
        printf("%.2lf", money);
    else
        printf("0.00");
    return 0;
}

发表于 2024-04-16 11:02:31 回复(0)
#include <stdio.h>

int main() {
    float price=0;
    int month=0;
    int date=0;
    int a=0;
    scanf("%f %d %d %d",&price,&month,&date,&a);
    if(month==11&&date==11)
    {
        if(a==1)
            price=price*0.7-50;
        else
            price=price*0.7;
    }
    else if(month==12&&date==12)
    {
        if(a==1)
            price=price*0.8-50;
        else
            price=price*0.8;
    }
    if(price<0)
        printf("0.00");
    else
        printf("%0.2f",price);

    return 0;
}
发表于 2024-04-02 20:01:44 回复(0)
#include <stdio.h>

int main() 
{
    int m = 0;
    int d = 0;
    int flag = 0;
    float money = 0.0f;

    scanf("%f%d%d%d", &money, &m, &d, &flag);

    //双12
    if(12 == m && 12 == d)
    {
        money *= 0.8;
    }
    //双11
    else if(11 == m && 11 == d)
    {
        money *= 0.7;
    }
    //优惠券
    if(flag)
    {
        money -= 50;

        //查看是否倒找钱
        //因为倒找钱的情况只会出现在有优惠券的情况下,所有放在此循环内
        if(money < 0)
        {
           money = 0;
        }
    }
 

    printf("%.2f\n", money);

    return 0;
}

编辑于 2024-03-18 16:38:42 回复(0)
#include <stdio.h>

int main() {
    double money;
    int a, b, c;
    while (scanf("%lf %d %d %d", &money, &a, &b, &c) != EOF) 
    { 
       double sum=0;
       if(a==11&&b==11)
       {
        sum=(money*0.7);
       }else if((a==12&&b==12))
       {
        sum=(money*0.8);
       }
       if((c==1&&a==11&&b==11)||(c==1&&a==12&&b==12))
       sum=sum-50;
       if(sum>0)
       printf("%.2lf\n",sum);
       else
        printf("%.2lf\n",0.00);
    }
    return 0;
}

发表于 2023-04-20 20:17:28 回复(0)