C++ 当分针和时针在给定的小时后重合的时间
当分针在一个小时内从12点移动到12点时,时针也会从上一个小时移动到下一个小时。
因此,每小时分针和时针都会重合一次。
问题陈述
给定一个输入小时,找出下一个小时内时针和分针重合的时间。
示例
输入 – 小时 = 4
输出 – 重合时间:240/11分钟。
我们将进一步通过方法来讨论解释。
输入 – 小时 = 5
输出 – 重合时间:300/11分钟。
解释和方法
#include<bits/stdc++.h>
using namespace std;
//Function to find the time in minutes.
void coincide_time(int hour){
//Temporary variable
int temp = 60*hour;
cout<<"Coinciding time: ";
cout<< temp<<"/"<<11<<" minutes"<<endl;
}
int main(){
//Initialize the input hour
int hour = 8;
//Function call
coincide_time(hour);
return 0;
}
输出
Coinciding time: 480/11 minutes
分析
时间复杂度 – O(1) [常数时间]
空间复杂度 – O(1) [常数空间]
结论
在本文中,我们找出了时针和分针重合的时间。我们使用单位方法推导出了公式,并通过几个例子进行了理解。然后,我们使用这个公式编写了一个伪代码,并用C++程序实现了解决方案。