# Arithmetic# Conditional Statements

e976 - Will You Make it?

🔗 前往 ZeroJudge 原題

題目描述

題目要求判斷在給定的時間內,是否能夠以給定的速度到達目的地。輸入包含三個整數:H (小時)、M (英里,表示距離)、S (英里/小時,表示速度)。需要計算是否能在 H 小時內行駛 M 英里,並輸出 "I will make it!" 或 "I will be late!"。

解題思路

題目可以直接使用算術運算來解決。計算所需時間為距離除以速度 (M / S)。如果所需時間小於或等於給定的小時數 (H),則輸出 "I will make it!",否則輸出 "I will be late!"。由於題目中沒有提到時間單位轉換,因此直接使用輸入的 H 作為小時數進行比較即可。

複雜度分析

  • 時間複雜度: O(1)
  • 空間複雜度: O(1)

程式碼

#include <stdio.h>
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c)>0){
		printf("%d %d %d. ",a,b,c);
		(a*c>=b)?puts("I will make it!\n"):puts("I will be late!\n");
	}
}

Discussion