题解 | #小乐乐定闹钟#
小乐乐定闹钟
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; }