一、题目要求
![](https://img-blog.csdnimg.cn/af7288b95bab4d6eb64eb0ef29a05dd7.png)
二、代码
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
//分切函数
vector<string> split(string str,char ch)
{
vector<string> results;
stringstream ss(str);
string temp;
while(getline(ss,temp,ch))
{
results.push_back(temp);
}
return results;
}
//打印结果
void dayin(int a,int b)
{
string str1;
string str2;
if (a<10)
{
str1 = "0"+to_string(a);
}
else
{
str1 = to_string(a);
}
if (b<10)
{
str2 = "0"+to_string(b);
}
else
{
str2 = to_string(b);
}
cout << str1 + ":" + str2 << endl;
}
int main()
{
//键盘输入
string str;
getline(cin,str);
//切分
vector<string> results;
results = split(str,' ');
//字符串转浮点数
int num1 = stoi(results[0]);
int num2 = stoi(results[1]);
//计算时间
int temp = num1 / num2;
//判断是否加1
if (num1 % num2 != 0)
{
temp = temp + 1;
}
//临界值
const int x = 60 * 8 -10;
//判断
if (temp < x)
{
int a = (8*60-temp-10)/60;
int b = (8*60-temp-10)%60;
dayin(a,b);
}
else if (temp > x)
{
if((temp-x) >= 24*60)
{
int a = (24*60-(temp-x)%(24*60))/60;
int b = (24*60-(temp-x)%(24*60))%60;
dayin(a,b);
}
else
{
int a = (24*60-(temp-x))/60;
int b = (24*60-(temp-x))%60;
dayin(a,b);
}
}
else
{
cout << "00:00" << endl;
}
return 0;
}