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