結果

問題 No.70 睡眠の重要性!
ユーザー aaaaaa
提出日時 2018-10-05 19:44:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,935 bytes
コンパイル時間 973 ms
コンパイル使用メモリ 101,732 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-02 16:47:34
合計ジャッジ時間 1,510 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>

using namespace std;


int main() {
	int i, j, k;
	int n;
	vector<string>s1, s2;
	vector<int>h1, h2, m1, m2;


	cin >> n;

	for (i = 0; i < n; i++) {
		string sa, sb;
		cin >> sa;
		s1.push_back(sa);

		string sh, sm;
		bool flag = false;

		for (j = 0; j < sa.length(); j++) {
			if (flag==false && sa[j] != ':') {
				sh += sa[j];
			}
			else if (flag == true && sa[j] != ':') {
				sm += sa[j];
				//flag = true;
			}

			if (sa[j] == ':') {
				flag = true;
			}
		}

		h1.push_back(stoi(sh));
		m1.push_back(stoi(sm));

		cin >> sb;
		s2.push_back(sb);

		sh = ""; sm = "";
		flag = false;

		for (j = 0; j < sb.length(); j++) {
			if (flag == false && sb[j] != ':') {
				sh += sb[j];
			}
			else if (flag == true && sb[j] != ':') {
				sm += sb[j];
				//flag = true;
			}

			if (sb[j] == ':') {
				flag = true;
			}
		}

		h2.push_back(stoi(sh));
		m2.push_back(stoi(sm));

	}

	int h = 0, m = 0;

	for (i = 0; i < n; i++) {
		if (h1[i] < h2[i]) {
			h += (h2[i] - h1[i]);
			
			if (m1[i] <= m2[i]) {

			}
			else if (m1[i] > m2[i]) {
				h--;
			}
		}
		else if (h1[i] > h2[i]) {
			h += (24 - h1[i]);
			h += h2[i];
			//h += (h2[i] - h1[i]);
			
			if (m1[i] <= m2[i]) {

			}
			else if (m1[i] > m2[i]) {
				h--;
			}
		}
		else if (h1[i] == h2[i]) {
			if (m1[i] < m2[i]) {

			}
			else if (m1[i] > m2[i]) {
				h += 23;
			}
		}

		if (m1[i] <= m2[i]) {
			m += (m2[i] - m1[i]);
		}
		else {
			m += (60 - m1[i]) + m2[i];
		}

		//cout << "i->" << i << "  " << "h->" << h << "  " << "m->" << m << endl;

	}

	cout << (h * 60) + m << endl;






	getchar();
	getchar();
	return 0;
}
0