Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int hours, minutes;
- cin >> hours >> minutes;
- int sumMinutes = hours * 60 + minutes + 15;
- int totalHours = sumMinutes / 60 % 24;
- int totalMinutes = sumMinutes % 60;
- if (totalMinutes < 10) {
- cout << totalHours << ":0" << totalMinutes << endl;
- }
- else {
- cout << totalHours << ':' << totalMinutes << endl;
- }
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- using namespace std;
- int main() {
- int hours, minutes;
- cin >> hours >> minutes;
- int sumMinutes = hours * 60 + minutes + 15;
- int totalHours = sumMinutes / 60 % 24;
- int totalMinutes = sumMinutes % 60;
- cout << totalHours << ':' << (totalMinutes < 10 ? "0" : "") << totalMinutes << endl;
- return 0;
- }
- Решение със setw() и setfill() на библиотеката iomanip:
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main() {
- int hours, minutes;
- cin >> hours >> minutes;
- int sumMinutes = hours * 60 + minutes + 15;
- int totalHours = sumMinutes / 60 % 24;
- int totalMinutes = sumMinutes % 60;
- cout << totalHours << ':' << setw(2) << setfill('0') << totalMinutes << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement