首页 > 试题广场 >

网购

[编程题]网购
  • 热度指数:71368 时间限制: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
public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double val = in.nextDouble();
        int moon = in.nextInt();
        int date = in.nextInt();
        int ticket = in.nextInt();

        if (moon == 11 && date == 11){  //双11
            if (ticket == 1){
                val = val * 0.7 - 50.0;
            } else {
                val = val * 0.7;
            }
        } else if (moon == 12 && date == 12){ //双12
            if (ticket == 1){
                val = val * 0.8 - 50.0;
            } else {
                val = val * 0.8;
            }
        }

        //不会倒找钱
        if (val < 0){
            val = 0;
        }

        System.out.printf("%.2f",val);
    }

发表于 2024-07-31 17:08:01 回复(0)
import java.util.Scanner;
import java.util.ArrayList;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s=in.nextLine();
String[] sList=s.split(" ");
ArrayList<Double> array=new ArrayList<Double>();
for(int i=0;i<4;i++){
array.add(Double.valueOf(sList[i]));
}
Double a=0.00;
if(array.get(1)==11){
a=array.get(0)*0.7-array.get(3)*50;
if(a<0){
System.out.println("0.00");
}else{
System.out.printf("%.2f",a);
}
}else if(array.get(1)==12){
a=array.get(0)*0.8-array.get(3)*50;
if(a<0){
System.out.println("0.00");
}else{
System.out.printf("%.2f",a);
}
}
}
}
发表于 2022-10-27 21:24:11 回复(0)
import java.util.*;
public class Main {
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        float val=sc.nextFloat();
        int moon=sc.nextInt();
        int date=sc.nextInt();
        int num=sc.nextInt();
        System.out.printf("%.2f",moon==12 &&date==12 ? num==1?  val*0.8-50<0 ? 0:  val*0.8-50 :  val*0.8 : moon==11 &&  date==11? num==1?   val*0.7-50<0? 0: val*0.7-50 : val*0.7 :   val );
        
        
        
        
        
        
        
        
    }    
}
// 第一次写那么长的代码
发表于 2022-09-11 21:03:46 回复(0)
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        float price=sc.nextFloat();
        int month=sc.nextInt(),day=sc.nextInt(),coupons=sc.nextInt();
        if(month==11&&day==11){
            price*=0.7;
            if(coupons==1) price-=50;
        }else if(month==12&&day==12){
            price*=0.8;
            if(coupons==1) price-=50;
        }
        if(price<0) price=0;
        System.out.printf("%.2f",price);
    }
}

发表于 2022-08-08 00:22:58 回复(0)
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()){
            //商品价格
            double goodPrice = scanner.nextDouble();
            //月份
            int month = scanner.nextInt();
            //日期
            int day = scanner.nextInt();
            //优惠券
            int coupons = scanner.nextInt();
            //折扣后的商品价格
            double discountGoodPrice = 0.0;
            //双11
            if(month == 11 && day == 11){
                if(coupons == 1){
                    discountGoodPrice = (goodPrice * 0.7) - 50.0;
                }else{
                    discountGoodPrice = goodPrice * 0.7;
                }
            }
            //双12
            if(month == 12 && day == 12){
                if(coupons == 1){
                    discountGoodPrice = (goodPrice * 0.8) - 50.0;
                }else{
                    discountGoodPrice = goodPrice * 0.8;
                }
            }
            //判断打折后加上使用优惠券的时候的最总价格,毕竟商家不能倒贴钱
            //打折后的价格小于等于0时,相当于白送,否则按正常价格输出
            if(discountGoodPrice <= 0.0){
                System.out.println("0.00");
            }else{
                System.out.println(String.format("%.2f",discountGoodPrice));
            }
            
      }
    }
}

发表于 2022-06-27 09:44:14 回复(0)
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double[] arr = new double[4];
        double price = 0;
        for (int i = 0; i < 4; i++) {
            arr[i] = sc.nextDouble();
        }
        if (arr[1] < 12) {
            price = 0.7 * arr[0];
        } else {
            price = 0.8 * arr[0];
        }
        if (arr[3] < 1) {
            System.out.printf("%.2f", price);
        } else {
            double m = (price - 50) > 0 ? (price - 50) : 0;
            System.out.printf("%.2f", m);
        }
    }
}

发表于 2022-06-17 11:07:40 回复(0)
import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner input=new Scanner(System.in);
        double val=input.nextDouble();
        int Mon=input.nextInt();
        int day=input.nextInt();
        int coupon=input.nextInt();
        double result=0;
        if(Mon==11&&day==11){
            if(coupon==1){
                result=val*0.7-50;
            }
            else
                result=val*0.7;
        }
        else if(Mon==12&&day==12){
            if(coupon==1){
                result=val*0.8-50;
            }
            else
                result=val*0.8;
        }
        System.out.print(result>0?String.format("%.2f",result):String.format("%.2f",0.00));
    }
}

发表于 2022-05-01 12:08:59 回复(0)
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 *
 * @Title          网购
 * @Description    KiKi非常喜欢网购,在一家店铺他看中了一件衣服,他了解到,
 * 如果今天是“双11”(11月11日)则这件衣服打7折,“双12” (12月12日)则这件衣服打8折,
 * 如果有优惠券可以额外减50元(优惠券只能在双11或双12使用),求KiKi最终所花的钱数。
 * 数据范围:衣服价格满足 1≤val≤100000
 * 输入描述:
 *      一行,四个数字,第一个数表示小明看中的衣服价格,第二和第三个整数分别表示当天的月份、当天的日期、第四个整数表示是否有优惠券(有优惠券用1表示,无优惠券用0表示)。 注:输入日期保证只有“双11”和“双12”。
 * 输出描述:
 *      一行,小明实际花的钱数(保留两位小数)。(提示:不要指望商家倒找你钱)
 * @author weijunfu<ijunfu @ qq.com>
 * @date 2022/03/16 23:44
 * @version 1.0.0
 *
 */

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        double v = in.nextDouble();
        int month = in.nextInt();
        int day = in.nextInt();
        int flag = in.nextInt();

        double discount = month == 11 ? 0.7 : 0.8;  // 折扣
        int coupons = flag == 0 ? 0 : 50;   // 优惠券

        double consume = v * discount - coupons;
        System.out.printf("%.2f", consume < 0 ? 0 : consume);

        in.close();
    }
}

发表于 2022-03-17 00:02:42 回复(0)
  import java.util.Scanner;  public class Main { public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);  String[] str = scanner.nextLine().split(" ");  double a = Double.parseDouble(str[0]);  int b = Integer.parseInt(str[1]);  int c = Integer.parseInt(str[2]);  int d = Integer.parseInt(str[3]);  double pay;  if (c == 11 && b == 11) { if (d == 1) { if (a * 0.7 > 50) {
                    pay = a * 0.7 - 50;  System.out.print(String.format("%.2f", pay));  } else {
                    System.out.print("0.00");  }
            } else {
                pay = a * 0.7;  System.out.print(String.format("%.2f", pay));  }
        } else if (b == 12 && c == 12) { if (d == 1) { if (a * 0.8 > 50) {
                    pay = a * 0.8 - 50;  System.out.print(String.format("%.2f", pay));  } else {
                    System.out.print("0.00");  }

            } else {
                pay = a * 0.8;  System.out.print(String.format("%.2f", pay));  }
        } else{
                System.out.print(String.format("%.2f", a));  }
        }
    }


发表于 2022-02-17 17:49:07 回复(0)
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double price = scanner.nextDouble();
        int date1 = scanner.nextInt();
        int date2 = scanner.nextInt();
        int n = scanner.nextInt();
        if (date1==11 && date2 == 11 && n==1){
            price = price * 0.7 - 50;
        }else if (date1==11 && date2 == 11 && n ==0){
            price = price * 0.7;
        }else if (date1==12 && date2 == 12 && n ==1){
            price = price *0.8 - 50;
        }else if (date1==12 && date2 == 12 && n ==0){
            price = price * 0.8;
        }
        if (price <= 0){
            System.out.println("0.00");
        }else {
            System.out.printf("%.2f",price);
        }
    }
}

发表于 2021-12-09 02:30:57 回复(0)
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        double price = scanner.nextDouble();
        int yue = scanner.nextInt();
        int ri = scanner.nextInt();
        int bool = scanner.nextInt();
        double sum = 0;
        if(yue == 11){
            if(bool == 1){
                sum = price * 0.7 - 50;
            }else{
                sum = price * 0.7;
            }
        }else{
            if(bool == 1){
                 sum = price * 0.8 - 50;
            }else{
                sum = price * 0.8;
            }
        }
        if(sum <= 0.00){
            System.out.printf("0.00");
        }else{
            System.out.printf("%.2f",sum);
        }
        
    }
}

发表于 2021-12-02 11:58:33 回复(0)
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] input = in.nextLine().split(" ");
        double discount;
        double price = Double.parseDouble(input[0]);
        if (input[1].equals(input[2]) && input[1].equals("11")){
            discount = 0.7;
        }else if (input[1].equals(input[2]) && input[1].equals("12")){
            discount = 0.8;
        }else {
            discount = 1.0;
        }
        price = price * discount;
        if (input[3].equals("1")){
            price -= 50.0;
        }
        if (price < 0){
            price = 0.00;
        }
        System.out.printf("%.2f", price);

    }
}

发表于 2021-10-19 17:47:02 回复(0)
import java.util.Scanner;

public class test35 {
    public static void main(String[] args) {
        double price;
        int month,day,count;
        Scanner sc1=new Scanner(System.in);
        while (sc1.hasNext()){
            price=sc1.nextDouble();
            month= sc1.nextInt();
            day=sc1.nextInt();
            count=sc1.nextInt();
            if(month==day && day==11){
               price=price*0.7;
            }
            if(month==day && day==12){
                price=price*0.8;
            }
            if(count==1){
                price=price-50;
            }
            if(price<0){
                price=0;
            }
            System.out.printf("%.2f",price);

        }
    }
}

发表于 2021-10-08 21:38:24 回复(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)
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)
import java.util.Scanner;
import java.text.DecimalFormat;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String str=sc.nextLine();
        String[] arr=str.split(" ");
        double price=Double.parseDouble(arr[0]);
        double mon=Double.parseDouble(arr[1]);
        double day=Double.parseDouble(arr[2]);
        double cou=Double.parseDouble(arr[3]);
        double num=0.00;
        DecimalFormat df=new DecimalFormat("######0.00");
        if(mon==11&&day==11){
             num=price*0.7;
            if(cou==1&&num>=50){
                System.out.print(df.format(num-50));
                
            }else if(cou==1&&num<50){
               System.out.print("0.00");
            }else{
                System.out.print(df.format(num));
            }
            
        }else if(mon==12&&day==12){
            num=price*0.8;
            if(cou==1&&num>=50){
                System.out.print(df.format(num-50));
                
            }else if(cou==1&&num<50){
               System.out.print("0.00");
            }else{
                System.out.print(df.format(num));
            }
        }
    }
}
发表于 2020-09-14 12:15:58 回复(0)
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
            String input = s.nextLine();
            String[] arrs = input.split(" ");
            double price = Double.valueOf(arrs[0]);
            String month = arrs[1];
            String day = arrs[2];
            String copon = arrs[3];
            double cost = 0.00;
            double discount1 = price * 0.7;
            double discount2 = price * 0.8;

            if ("11".equals(month) && "11".equals(day)) {
                if ("1".equals(copon)) {
                    if (discount1 < 50) {
                        System.out.println("0.00");
                    } else {
                        System.out.printf("%.2f", discount1 - 50);
                    }
                } else if ("0".equals(copon)) {
                    System.out.printf("%.2f", discount1);
                }

            } else if ("12".equals(month) && "12".equals(day)) {
                if ("1".equals(copon)) {
                    if (discount2 < 50) {
                        System.out.println("0.00");
                    } else {
                        System.out.printf("%.2f", discount2 - 50);
                    }
                } else if ("0".equals(copon)) {
                    System.out.printf("%.2f", discount2);
                }
            } else {
                System.out.printf("%.2f", price);
            }
        }
}
麻烦
发表于 2020-07-28 17:26:26 回复(0)