返回题解分享
讨论 / 题解分享/ 帖子详情

时间显示(编程题) - 题解

我三年级,我写完啦

#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
using namespace std;
int h,m,s;

int main()
{
	//46800
	long long n;
	cin>>n;
	n /= 1000;
	h = n / 60 / 60 % 24;
	m = n / 60 % 60;
	s = n % 60 % 60;
	if(h == 0)
	{
		cout<<"00:";
	}
	else if(h > 0 && h < 10)
	{
		cout<<"0"<<h<<":";
	}
	else
	{
		cout<<h<<":";
	}
	if(m == 0)
	{
		cout<<"00:";
	}
	else if(m > 0 && m < 10)
	{
		cout<<"0"<<m<<":";
	}
	else
	{
		cout<<m<<":";
	}
	if(s == 0)
	{
		cout<<"00";
	}
	else if(s > 0 && s < 10)
	{
		cout<<"0"<<s;
	}
	else
	{
		cout<<s;
	}
	
	
	return 0;            
}
0 回复 0 转发 1 喜欢 2 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!