Click
Here to go back to the homepage.
Saving Daylight Solution:
#include <bits/stdc++.h>
using namespace std;
std::vector<std::string> stringSplit(const std::string s, char delimiter){
std::vector<std::string> tokens;
std::string token;
std::istringstream tokenStream(s);
while (getline(tokenStream, token, delimiter)){
tokens.push_back(token);
}
return tokens;
}
int main(){
// #ifndef TESTING
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
string line;
while(getline(cin, line)){
stringstream ss(line);
string month;
int day, year;
ss >> month >> day >> year;
string rise, set;
ss >> rise >> set;
auto riseTime = stringSplit(rise, ':');
auto setTime = stringSplit(set, ':');
int setM = stoi(setTime[1]);
int riseM = stoi(riseTime[1]);
int setH = stoi(setTime[0]);
int riseH = stoi(riseTime[0]);
int totalM = setM - riseM;
if(totalM < 0){
totalM += 60;
setH--;
}
int totalH = setH - riseH;
cout << month << " " << day << " " << year << " " << totalH << " hours " << totalM << " minutes" << endl;
}
return 0;
}