演算与实际有出入
查看原帖
演算与实际有出入
908595
WillowCatkin楼主2022/12/8 20:51

输入1000 5 期望输出04:30 但实际输出为07:30

自己的思路: s——路程 v——速度 t——所需时间(总时间,单位为分钟) m——所需时间(分钟) h——所需时间(小时)

#include <bits/stdc++.h>
using namespace std;
int main() 
{
	int s,v,t,m,h,M=50,H=7;//
	scanf("%d%d",&s,&v);//输入1000 5
	t=s/v; //计算所需总时间
	
	if(s%v!=0) t++; //向上取整
	
	h=t/60; //计算所需小时
	
	if(h=0) m=t; 
	else m=t%60; //计算所需分钟

	if(M-m<0)
		(h=h-1,m=m+60,M=M-m);
	else
		M=M-m; //计算最晚到达的分钟
	
	if(H-h<0)
		(H=H+24,H=H-h);
	else H=H-h; //计算最晚到达的小时
	
	if((H<10)&&(M<10))
		 printf("0%d:0%d",H,M);
	else if((H>=10)&&(M>=10))
			printf("%d:%d",H,M);
		else if((H<10)&&(M>=10))
				printf("0%d:%d",H,M);
			else if((H>=10)&&(M<10))
					printf("%d:0%d",H,M); //分情况添0
	return 0;
}
}
2022/12/8 20:51
加载中...