首页 > 试题广场 >

计算商场折扣

[编程题]计算商场折扣
  • 热度指数:44181 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解

牛牛商场促销活动:

满100全额打9折;

500全额8折;

2000全额7折;

满5000全额打6折;
且商场有抹零活动,不足一元的部分不需要付款(类型强制转换)
牛大姨算不清楚自己应该付多少钱,请你帮忙算一下


输入描述:
牛大姨账单钱数(int类型)


输出描述:
参加活动后,牛大姨应付钱数(int类型)
示例1

输入

654

输出

523
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int price = console.nextInt();
        int cost = 0;
        if (price >=5000) {
            cost=(int)(price*0.6);
        }else if(price>=2000){
            cost=(int)(price*0.7);
        }else if(price>=500){
            cost=(int)(price*0.8);
        }else if(price>=100){
            cost=(int)(price*0.9);
        }else{
            cost=price;
        }
        System.out.println(cost);
    }
}

发表于 2024-04-06 21:56:01 回复(0)
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int price = console.nextInt();
        int cost = 0;

        //write your code here......
        cost = (int)(price * (price > 5000 ? 0.6 :
                              price >= 2000 ? 0.7 :
                              price >= 500 ? 0.8 :
                              price >= 100 ? 0.9 : 1));

        System.out.println(cost);
    }
}

发表于 2024-03-14 21:43:32 回复(0)
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int money = sc.nextInt();
        if (money >= 100 && money < 500) {
            money = (int) (money * 0.9);
        } else if (money >= 500 && money < 2000) {
            money = (int) (money * 0.8);
        } else if (money >= 2000 && money < 5000) {
            money = (int) (money * 0.7);
        } else if (money >= 5000) {
            money = (int) (money * 0.6);
        }

        System.out.println(money);

    }
}

发表于 2023-11-03 21:03:39 回复(0)
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int price = console.nextInt();
        int cost = 0;

        //write your code here......
        if(price >= 5000){
            cost = (int)(price * 0.6);
        }
        else if(price >= 2000){
            cost = (int)(price * 0.7);
        }
        else if(price >= 500){
            cost = (int)(price * 0.8);
        }
        else if(price >= 100){
            cost = (int)(price * 0.9);
        }
        else{
            cost = price;
        }

        System.out.println(cost);
    }
}

发表于 2023-02-09 10:23:17 回复(0)
import java.util.*;
public class Main {
   public static void main(String[] args){
       Scanner in = new Scanner(System.in);
       int P = in.nextInt();
       int C = 0;
       if(P >= 100 && P < 500){
        System.out.println(P*0.9);
       }else if(P >= 500 && P <2000) {
          System.out.println(P*0.8);
       }else if(P >= 2000 && P < 5000){
           System.out.println(P*0.7);
       }else if(P >= 5000){
           System.out.println(P*0.6);
       }
       }
   }

发表于 2022-11-28 00:13:16 回复(1)
public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        if (in.hasNextInt()) {
            int a = in.nextInt();
            double b=a;
            if(a>=100){
                b=a*0.9;
                if(a>=500)
                    b=a*0.8;
                    if(a>=2000)
                        b=a*0.7;
                        if(a>=5000)
                            b=a*0.6;
            }
            System.out.println((int)b);
        }
        in.close();
    }

发表于 2022-09-25 18:42:09 回复(0)
public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int price = console.nextInt();
        int cost = 0;

        //write your code here......
        double discount = 1;
            
        if(price >= 5000) {
            discount = 0.6;
        } else if(price >= 2000) {
            discount = 0.7;
        } else if(price >= 500) {
            discount = 0.8;
        } else if(price >= 100) {
            discount = 0.9;
        }
        cost = (int)(price * discount);

        System.out.println(cost);
    }
}

发表于 2022-09-14 15:39:35 回复(0)
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int price = console.nextInt();
        int cost = 0;
        double d;
        d=(double)cost;
        if(price>=5000)
            d=price*0.6;
        else if(price>=2000&&price<5000)
            d=price*0.7;
        else if(price>=500&&price<2000)
            d=price*0.8;
        else
            d=price;
        cost=(int)d;
        System.out.println(cost);
    }
}
发表于 2022-09-10 16:20:38 回复(0)
看了一下题解和讨论,好像大部分人都用的是if,else的语句,没有用switch的吗?想看看大佬们用switch写的
发表于 2022-08-25 09:34:42 回复(1)
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int price = console.nextInt();
        int cost = 0;

        if (price >= 100 & price < 500) {
            cost = (int) (price * 0.9);
        } else if (price >= 500 & price < 2000) {
            cost = (int) (price * 0.8);
        } else if (price >= 2000 & price < 5000) {
            cost = (int) (price * 0.7);
        } else if (price >= 5000) {
            cost = (int) (price * 0.6);
        } else {
            cost = price;
        }

        System.out.println(cost);
    }

发表于 2022-08-09 23:12:20 回复(0)
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int price = console.nextInt();
        double cost = 0;
        if(price>=5000) cost=price*0.6;
        else if(price>=2000) cost=price*0.7;
        else if(price>=500) cost=price*0.8;
        else if(price>=100) cost=price*0.9;
        else cost=price;

        System.out.println((int)cost);
    }
}

发表于 2022-07-26 18:16:19 回复(0)
比较菜,一开始还在用switch写,写好了跑不动,查了以后才知道case后面不能方比较的语句。😐
发表于 2022-06-22 12:18:53 回复(2)
public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int price = console.nextInt();
        int cost = 0;

        //write your code here......
        if(price >= 5000){
            cost = (int)(price * 0.6);
        }else if(price >= 2000){
            cost = (int)(price * 0.7);
        }else if(price >= 500){
            cost = (int)(price * 0.8);
        }else if(price >= 100){
            cost = (int)(price * 0.9);
        }else{
            cost = price;
        }

        System.out.println(cost);
    }
}

发表于 2022-06-17 17:21:36 回复(0)
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int price = console.nextInt();
        int cost = 0;

        //write your code here......
        if(price<100){
            cost=(int)price;
        }
        else if(price>=100&&price<500){
            cost=(int)(price*0.9);
        }else if(price>=500&&price<2000){
            cost=(int)(price*0.8);
        }else if(price>=2000&&price<5000){
            cost=(int)(price*0.7);
        }else if(price>=5000){
            cost=(int)(price*0.6);
        }
        System.out.println(cost);
    }
}
发表于 2022-06-13 11:23:39 回复(0)
        //write your code here......
        if(price >= 5000){
            cost = (int)(price * 0.6);
        }else if(price >= 2000){
            cost = (int)(price * 0.7);
        }else if(price >= 500){
            cost = (int)(price * 0.8);
        }else if(price >= 100){
            cost = (int)(price * 0.9);
        }else{
            cost = price;
        }


发表于 2022-06-06 12:48:45 回复(3)
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int price = console.nextInt();
        int cost = 0 ;

        //write your code here......
        if(price < 500 && price >= 100){
          cost =(int)(price * 0.9);
        }else if( price < 2000 && price >= 500){
           cost =(int)(price * 0.8);
        }else if( price < 5000 && price >= 2000){
           cost = (int)(price * 0.7);
        }else if( price >= 5000){
          cost = (int)(price * 0.6);
        }else if(price > 1 && price < 100){
          cost = (int) price; 
        }else {
         cost = 0;
        }

        System.out.println(cost);
    }
}

发表于 2022-05-05 22:39:12 回复(0)
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int price = console.nextInt();
        int cost = 0;
        float f =1.0f;
        //price = (int) price/100;

        //write your code here......
        switch(price/100){
            case 0 :  f=1.0f ;
                break;
            case 1:
            case 2:
            case 3: 
            case 4:  f=0.9f; 
                break;
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
            case 17:
            case 18:
            case 19 :  f=0.8f; 
                break;
            case 20:
            case 21:
            case 22:
            case 23:
            case 24:
            case 25:
            case 26:
            case 27:
            case 28:
            case 29:
            case 30:
            case 31:
            case 32:
            case 33:
            case 34:
            case 35:
                case 36:
                case 37:
                case 38:
                case 39:
                case 40:
                case 41:
                case 42:
                case 43:
                case 44:
                case 45:
                case 46:
                case 47:
                case 48:
                case 49 :  f=0.7f;
                break;
            default : f=0.6f;
        }

        cost = (int) Math.floor(price*f);
       // cost = (int) cost;
        System.out.println(cost);
    }
}
发表于 2022-04-26 16:22:36 回复(0)