列表

详情


JAVA5. 计算商场折扣

描述

牛牛商场促销活动:

满100全额打9折;

500全额8折;

2000全额7折;

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

输入描述

牛大姨账单钱数(int类型)

输出描述

参加活动后,牛大姨应付钱数(int类型)

示例1

输入:

654

输出:

523

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Java 解法, 执行用时: 12ms, 内存消耗: 9384KB, 提交时间: 2022-08-06

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        int i = Integer.parseInt(str[0]);
        double cost = 0;
        if(i >= 5000){
            cost = 0.6*i;
        }else if(i >= 2000){
            cost = 0.7*i;
        }else if(i >= 500){
            cost = 0.8*i;
        }else if(i >= 100){
            cost = 0.9*i;
        }else{
            cost = i;
        }

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

Java 解法, 执行用时: 12ms, 内存消耗: 9400KB, 提交时间: 2022-05-14

import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int price = Integer.valueOf(line[0]);
        int cost = 0;
 
        //write your code here......
        if (price < 100) {
            cost = price;
        }else if (price < 500) {
            cost = (int)(price * 0.9);
        } else if (price < 2000) {
            cost = (int)(price * 0.8);
        } else if (price < 5000) {
            cost = (int)(price * 0.7);
        } else {
            cost = (int)(price * 0.6);
        }
 
        System.out.println(cost);
    }
}

Java 解法, 执行用时: 12ms, 内存消耗: 9476KB, 提交时间: 2022-05-11

import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int price = Integer.valueOf(line[0]);
        int cost = 0;

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

        System.out.println(cost);
    }
}

Java 解法, 执行用时: 12ms, 内存消耗: 9532KB, 提交时间: 2022-06-30

import java.util.*;
import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int price=Integer.parseInt(br.readLine());
        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);
    }
}

Java 解法, 执行用时: 12ms, 内存消耗: 9552KB, 提交时间: 2022-03-07

import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException{
        try(BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out)){
            String[] line=br.readLine().split(" ");
            int cost=Integer.parseInt(line[0]);
            float rate=1.0F;
            if(cost>=100&&cost<500){
                rate=0.9f;
            }else if(cost>=500&&cost<2000){
                rate=0.8f;
            }else if(cost>=2000&&cost<5000){
                rate=0.7f;
            }else if(cost>=5000){
                rate=0.6f;
            }
            cost=(int)(cost*rate);
            pw.write(cost+"");
            pw.flush();
        }
    }
}

上一题