close

英文題目

 

python

# 2020/1/1
# 解題思路
# 後面的時間減前面的時間
# 如果是負的就加上1440
# 因為一天最多1440分鐘

while 1:
    time = input()  # 輸入
    if time == '0 0 0 0':  # 結束測資
        break

    time = time.split(' ')  # 把測資以空格分開
    ctime = list(map(int, time))  # 將list裡的str改成int

    hr = -ctime[0]+ctime[2]  # 計算小時
    mins = -ctime[1]+ctime[3]  # 計算分鐘

    ans = hr*60+mins+1440 if hr*60+mins < 0 else hr*60+mins  # 答案
    print(ans)  # 輸出

 

C++

/*
2019/1/10
解題思路
後面的時間減前面的時間
如果是負的就加上1440
因為一天最多1440分鐘
*/ 
#include <iostream>
using namespace std;

int main()
{
	while(1)
	{
		int t0,t1,t2,t3;
		
		cin>>t0>>t1>>t2>>t3;//輸入測資 
		if(t0+t1+t2+t3==0)//結束測資 
		{
			break;
		}
		
		if((t2-t0)*60+t3-t1>0)//後面時間大於前面時間 
		{
			cout<<(t2-t0)*60+t3-t1;	
		} 
		else//後面時間小於前面時間
		{
			cout<<1440+(t2-t0)*60+t3-t1;	
		} 
		cout<<endl;
	}
	return 0;
}

 

未命名1.png

arrow
arrow
    文章標籤
    CPE歷屆試題 Alarm Clock
    全站熱搜
    創作者介紹
    創作者 豪CO 的頭像
    豪CO

    程式道路,必為豐富

    豪CO 發表在 痞客邦 留言(0) 人氣()