題目:停車費計算
說明:計算出停車時間後,依據題目設定算出最後需支付的停車費用
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int min1 = sc.nextInt();
int s1 = sc.nextInt();
int min2 = sc.nextInt();
int s2 = sc.nextInt();
int time1 = min1 * 60 + s1;
int time2 = min2 * 60 + s2;
int result = 0;
int time = time2 - time1;
if(time < 120 && time > 0) {
result = (time) / 30 * 30;
}else if(time <= 240 && time >= 120){
result = (time-120) / 30 * 40 + 120;
}else{
result = (time-240) / 30 * 60 +120 +160;
}
System.out.println(result);
}
}