ZJU1112

本文介绍了一个使用 C++ 编写的程序,该程序能够接收初始时间和最终时间作为输入,并计算两个时间之间的间隔(称为“通过次数”)。程序利用了模运算来确保时间计算的准确性,即使最终时间早于初始时间也能正确处理。
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	int startHour, startMinute, finalHour, finalMinute;
	int sMinute, fMinute;
	int pass;
	while (cin >> startHour >> startMinute >> finalHour >> finalMinute)
	{
		cout << "Program 3 by team X" << endl
			<< "Initial time  Final time  Passes" << endl;
		sMinute = (startHour % 12) * 60 + startMinute;
		fMinute = (finalHour % 12) * 60 + finalMinute;
		pass = (fMinute * 11) / 720 - (sMinute * 11) / 720;
		if(sMinute > fMinute) pass += 11;
		cout << "      " << setw(2) << setfill('0') << startHour << ":" << setw(2) << setfill('0') << startMinute << "      " 
			<< setw(2) << setfill('0') << finalHour << ":" << setw(2) << setfill('0') << finalMinute << "      " << pass << endl;
		cout << "End of program 3 by team X" << endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值