fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int N, X, Y;
  5. printf("請輸入 N、X、Y (0 < Y): ");
  6. scanf("%d %d %d", &N, &X, &Y);
  7.  
  8. int temperature = 20;
  9.  
  10. if (N % 2 == 0) {
  11. N -= 1; // 如果N是偶數,減1使其變成奇數,然後執行一次冷卻操作
  12. temperature -= Y;
  13. if (temperature < 20) {
  14. temperature = 20;
  15. }
  16. }
  17.  
  18. // 使用循環計算最高溫度
  19. for (int i = 1; i <= N ; i++) {
  20. temperature += X;
  21. temperature -= Y;
  22. if (temperature < 20) {
  23. temperature = 20;
  24. }
  25. }
  26.  
  27. printf("%d\n", temperature);
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 5544KB
stdin
4 20 3
stdout
請輸入 N、X、Y (0 < Y): 71