結果

問題 No.70 睡眠の重要性!
ユーザー dgd1724dgd1724
提出日時 2016-09-20 07:03:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,567 bytes
コンパイル時間 758 ms
コンパイル使用メモリ 93,648 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-08-10 23:26:11
合計ジャッジ時間 1,234 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES	//M_PI
#include <iostream>			//std::cout, std::cin
#include <string>			//std::string
#include <vector>			//std::vector
#include <valarray>			//std::valarray	数値のみの一次配列
#include <algorithm>		//std::sort
#include <time.h>			//localtime_s
#include <cstdlib>			//abs
#include <cmath>			//abs, std::pow, sqrt, sin, cos,
#include <fstream>			//std::ifstream
#include <iomanip>			//std::setprecision
#include <random>			//std::random(C++11)
#include <numeric>			//std::accumulate

int main(void) {

	
	//test用
	//std::ifstream in("test.txt");
	//std::cin.rdbuf(in.rdbuf());

	int N;
	std::string str1, str2;
	std::cin >> N;

	int ans = 0;
	for (int i = 0; i < N; i++) {

		std::cin >> str1 >> str2;

		std::string temp;
		int s_h, s_m, w_h, w_m;
		
		int j = 0;
		while (str1[j] != ':') {
			temp.push_back(str1[j]);
			j++;
		}
		s_h = std::stoi(temp);

		j++;
		temp.clear();
		while (j < str1.length()) {
			temp.push_back(str1[j]);
			j++;
		}
		s_m = std::stoi(temp);

		j = 0;
		temp.clear();
		while (str2[j] != ':') {
			temp.push_back(str2[j]);
			j++;
		}
		w_h = std::stoi(temp);

		j++;
		temp.clear();
		while (j < str2.length()) {
			temp.push_back(str2[j]);
			j++;
		}
		w_m = std::stoi(temp);

		if (s_h > w_h) {
			ans += (24 - s_h - 1) * 60 + (60 - s_m) + w_h * 60 + w_m;
		}
		else if (s_h < w_h) {
			ans += (w_h - s_h - 1) * 60 + (60 - s_m) + w_m;
		}
		else {
			if (w_m >= s_m) {
				ans += w_m - s_m;
			}
			else {
				ans += 23 * 60 + (60 - s_m) + w_m;
			}
		}
	}

	std::cout << ans << std::endl;
}


0