-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspavanac.cpp
63 lines (50 loc) · 1.16 KB
/
spavanac.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* @file aaah.cpp
* @author William Weston
* @brief Spavanac Problem from Kattis
* @version 0.1
* @date 2023-06-15
*
* @copyright Copyright (c) 2023
*
* Source: https://open.kattis.com/problems/spavanac
*/
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
struct Time
{
int hours = 0;
int minutes = 0;
};
auto operator<<( std::ostream& out, Time const& time ) -> std::ostream&;
auto forty_five_minutes_earlier( int hours, int minutes ) -> Time;
auto
main() -> int
{
int hours;
int minutes;
while( std::cin >> hours >> minutes )
std::cout << forty_five_minutes_earlier( hours, minutes ) << '\n';
return EXIT_SUCCESS;
}
auto
forty_five_minutes_earlier( int hours, int minutes ) -> Time
{
if ( minutes >= 45 )
return { hours, minutes - 45 };
auto const new_minutes = 60 - std::abs( minutes - 45 );
return ( hours > 0 )
? Time{ --hours, new_minutes }
: Time{ 23, new_minutes };
}
auto
operator<<( std::ostream& out, Time const& time ) -> std::ostream&
{
using namespace std::literals;
out << time.hours
<< ' ' // << ( ( time.minutes < 10 ) ? " 0"s : " "s )
<< time.minutes;
return out;
}