#35275: 注意!!! 只能使用+=

liaoweichen1024@gmail.com (M_SQRT)

School : 新北市立新莊高級中學
ID : 195452
IP address : [118.166.135.212]
2023-06-06 17:40:53
k570. pA. 關於友善時光這件事 -- | From: [118.166.136.101] | Post Date : 2023-05-21 03:30

double d = 0.9_999_999_999_999_999;
System.out.println(d); //0.9999999999999999
System.out.println((int)d); //0
int x = 0;
System.out.println(x+=d); //0
x = 5;
System.out.println(x+=d); //6

Java OOP寫法

public class k570 {
    //物件為超商
    //超商的折扣
    double off;
    //折扣的時段
    int[][] businessHours;

    //物件初始化
    k570(int[][] businessHours, double off) {
        this.businessHours = businessHours;
        this.off = off;
    }

    //類別(主)函式
    public static void main(String[] args) throws java.io.IOException {
        //宣告四間超商
        final int[] zero = {0, 1};
        k570[] market = {new k570(new int[][] {{1080, 1440}, zero}, 0.7),
                new k570(new int[][] {{600, 1440}, zero}, 0.7),
                new k570(new int[][] {{600, 1021}, {1200, 1440}, zero}, 0.65),
                new k570(new int[][] {{990, 1351}}, 0.6)};
        int i, t, m, ans=0;
        //輸入資料
        for(;;) {
            ans += market[i].getMoney(t, m);
        }
        //輸出ans

    }
    //物件函式
    //算出此時段的價格
    int getMoney(int time, int money) {
        for(int[] arr: businessHours)
            if(arr[0]<=time&&time<arr[1])
                return (int)(money*off);
        return money;
    }

}

ZeroJudge Forum