PAT 乙级 1026 程序运行时间 (15分) --- [整数除法得全值,四舍五入]

在这里插入图片描述

四舍五入思路一:

#include<bits/stdc++.h>
using namespace std;

int main(){
    
    
	double c1,c2;
	scanf("%lf%lf",&c1,&c2);
	double c = c2-c1;
	int time = round(c/100);//四舍五入 (round(c/100)是double型)
	int h,m,s;
	h=time/3600;
	m=time%3600/60;
	s=time%60;
	printf("%02d:%02d:%02d",h,m,s);
	return 0;
} 

四舍五入思路二:

	//"/100"之后要判断四舍五入,所以判断后两位 >=50与否! 
	if(time%100>=50){
		time=time/100+1;
	}
	else{
		time=time/100;
	}
#include<bits/stdc++.h>
using namespace std;

int main(){
    
    
	int c1,c2;
	scanf("%d%d",&c1,&c2);
	int time = c2-c1;
	//"/100"之后要判断四舍五入,所以判断后两位 >=50与否! 
	if(time%100>=50){
    
    
		time=time/100+1;
	}
	else{
    
    
		time=time/100;
	}
	int h,m,s;
	h=time/3600;
	m=time%3600/60;
	s=time%60;
	printf("%02d:%02d:%02d",h,m,s);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44926962/article/details/109564424
今日推荐