// No.70 睡眠の重要性! // https://yukicoder.me/problems/no/70 // #include <iostream> #include <vector> #include <string> #include <algorithm> #include <regex> using namespace std; vector<string> split_input(); int main() { unsigned int N; cin >> N; unsigned int slept = 0; vector<string> st; for (auto i = 0; i < N; ++i) { st = split_input(); int start_time = stoi(st[0])*60 + stoi(st[1]); st = split_input(); int end_time = stoi(st[0])*60 + stoi(st[1]); if (start_time > end_time) end_time += 24 * 60; slept += (end_time - start_time); } cout << slept << endl; } vector<string> split_input() { // :文字区切りのデータを分割しその結果を返す。 vector<string> res; string input_txt; cin >> input_txt; regex rx(R"(:)"); sregex_token_iterator it(input_txt.begin(), input_txt.end(), rx, -1); sregex_token_iterator end; while (it != end) { if (*it != "") res.push_back(*it++); else it++; } return res; }