說明:將小時減掉 15 後,有機會是負數,所以再加上 24,而超過 24 多出來的就取餘數。
Java 版
import java.util.Scanner;
public class D050 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
String input = in.nextLine();
int a = Integer.parseInt(input);
int r = (a - 15 + 24) % 24;
System.out.println(r);
}
}
}
Python 版 (2022.07)while True:
try:
h = int(input())
print((h - 15 + 24) % 24)
except:
break
沒有留言:
張貼留言