Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- const int64_t dayToSec = 24 * 60 * 60;
- int64_t FromTimeToSeconds(const std::string& str) {
- int64_t h = 0, m = 0, s = 0, t = 0;
- size_t index = 0;
- std::string hours, minutes, seconds;
- int counter = 0;
- for (char i : str) {
- if (i == ':') {
- counter++;
- }
- }
- if (counter == 2) {
- while (str[index] != ':') {
- hours += str[index];
- index++;
- }
- index++;
- for (char hour : hours) {
- h = h * 10 + static_cast<int>(hour) - '0';
- }
- t += h * 60 * 60;
- }
- if (counter >= 1) {
- while (str[index] != ':') {
- minutes += str[index];
- index++;
- }
- index++;
- for (char minute : minutes) {
- m = m * 10 + static_cast<int>(minute) - '0';
- }
- t += m * 60;
- }
- while (index < str.size()) {
- seconds += str[index];
- index++;
- }
- for (char second : seconds) {
- s = s * 10 + static_cast<int>(second) - '0';
- }
- return t + s;
- }
- std::string timerAlarm(int64_t start, int64_t timer) {
- std::string result;
- int64_t days = 0;
- int64_t time = (start + timer) % (dayToSec);
- if (time < start) {
- ++days;
- }
- days += timer / dayToSec;
- int64_t hours = time / (60 * 60);
- int64_t minutes = (time % (60 * 60)) / 60;
- int64_t seconds = time % 60;
- if (hours < 10) {
- result += '0';
- }
- result += (std::to_string(hours) + ':');
- if (minutes < 10) {
- result += '0';
- }
- result += (std::to_string(minutes) + ':');
- if (seconds < 10) {
- result += '0';
- }
- result += std::to_string(seconds);
- if (days >= 1) {
- result += ("+" + std::to_string(days) + " days");
- }
- return result;
- }
- int main() {
- std::string start;
- std::string timer;
- std::cin >> start;
- std::cin >> timer;
- int64_t int_start = FromTimeToSeconds(start);
- int64_t int_timer = FromTimeToSeconds(timer);
- std::cout << timerAlarm(int_start, int_timer);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement