--- tags: Cmoney_Java題目 --- Java_Cmoney_ft7108 === ![](https://i.imgur.com/MF9C1DO.png) ![](https://i.imgur.com/0MtACCF.png) 1.需要的 function --- 1.1 主程式 --- 1. 判斷是否是-1 2. 如果是偶數天C-=20(因為每兩天C消耗會減少20,但不低於50) 3. 用while迴圈減去超出體力的運動次數 ```java= import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int C = sc.nextInt(); int G = sc.nextInt(); int max = 1000; int count = 1; while (true) { int N = sc.nextInt(); if (N == -1) break; if (count % 2 == 0) { C -= 20; if (C <= 50) C = 50; } while (max <= N * C) { N--; } max += N * C / 100 * G; count++; } System.out.println(max); } } ```