結果

問題 No.70 睡眠の重要性!
ユーザー ku_material_roku_material_ro
提出日時 2016-09-14 23:46:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,071 bytes
コンパイル時間 465 ms
コンパイル使用メモリ 59,936 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-28 13:44:50
合計ジャッジ時間 919 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int main(){
	int n;
	int a,b;
	int H, h, M, m;
	int dh, dm;
	int ans = 0;
	string s1;
	string s2;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> s1;
		cin >> s2;
		a = s1.find(":");
		if (a == 1){
			H = s1[0] - '0';
			if (s1[3] == '\0'){
				M = s1[2] - '0';
			}
			else{
				M = (s1[2] - '0') * 10 + (s1[3] - '0');
			}
		}
		else{
			H = (s1[0] - '0') * 10 + (s1[1] - '0');
			if (s1[4] == '\0'){
				M = s1[3] - '0';
			}
			else{
				M = (s1[3] - '0') * 10 + (s1[4] - '0');
			}
		}
		b = s2.find(":");
		if (b == 1){
			h = s2[0] - '0';
			if (s2[3] == '\0'){
				m = s2[2] - '0';
			}
			else{
				m = (s2[2] - '0') * 10 + (s2[3] - '0');
			}
		}
		else{
			h = (s2[0] - '0') * 10 + (s2[1] - '0');
			if (s2[4] == '\0'){
				m = s2[3] - '0';
			}
			else{
				m = (s2[3] - '0') * 10 + (s2[4] - '0');
			}
		}
		dh = h - H;
		dm = m - M;
		if (dm < 0){
			dm += 60;
			dh -= 1;
		}
		if (dh < 0){
			dh += 24;
		}

		ans += dh * 60 + dm;
	}
		cout << ans << endl;

	






	return 0;
}
0