题解 | #小乐乐定闹钟#

小乐乐定闹钟

https://www.nowcoder.com/practice/0f7e422e12be4a7f9958ca2a82abc775

#include<iostream>
#include<iomanip>
//#include<format>

int main(int argc, char* argv[])
{
	unsigned short hours{},minutes{};
	unsigned int k{};
	std::cin >> hours;
	getchar();
	std::cin >> minutes >> k;
	if (hours < 24 && minutes<60)
	{
		hours = (hours + (minutes + k) / 60) % 24;
		minutes += k % 60;
		minutes %= 60;
	}
	/*c++20采用std::format字符串初始化,
	其格式说明符的一般形式如下[[fill]align][sign][#][0][:width][.precesion][type]
	std::cout << std::format("{:02d}:{:02d}", hours, minutes);*/

	std::cout.setf(std::ios::fixed,std::ios::right);
	std::cout << std::setfill('0') << std::setw(2) << hours << ":"<< std::setw(2) << minutes;
}

全部评论

相关推荐

Lorn的意义:你这标个前端是想找全栈吗?而且项目确实没什么含金量,技术栈太少了,边沉淀边找吧 现在学院本想就业好一点四年至少得高三模式两年加油吧
点赞 评论 收藏
分享
06-26 17:24
已编辑
宁波大学 golang
迷失西雅图:别给,纯kpi,别问我为什么知道
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务