結果

問題 No.70 睡眠の重要性!
ユーザー yo-kondoyo-kondo
提出日時 2018-03-10 23:07:23
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,337 bytes
コンパイル時間 13,216 ms
コンパイル使用メモリ 229,652 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 18:30:28
合計ジャッジ時間 13,828 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

// エントリポイント
func main() {
	in := bufio.NewScanner(os.Stdin)
	// 記録の個数
	in.Scan()
	input1 := in.Text()
	// 1 回の睡眠あたりの寝た時刻と起きた時刻の記録
	input2 := make([]string, 0)
	for in.Scan() {
		input2 = append(input2, in.Text())
	}

	fmt.Println(timeOfSleeping(input1, input2))
}

// 睡眠時間の合計を分にして返す。
func timeOfSleeping(lineNum string, sleep []string) string {
	// 定数 1日の分
	const dayMinute = 24 * 60
	_ = lineNum
	minute := 0
	for _, v := range sleep {
		// 寝た時間と起きた時間
		sp := strings.Split(v, " ")

		// 寝た時間(分)
		sleepSp := strings.Split(sp[0], ":")
		sleepH, _ := strconv.Atoi(sleepSp[0])
		sleepM, _ := strconv.Atoi(sleepSp[1])
		sleepMinute := sleepH*60 + sleepM

		// 起きた時間(分)
		getupSp := strings.Split(sp[1], ":")
		getupH, _ := strconv.Atoi(getupSp[0])
		getupM, _ := strconv.Atoi(getupSp[1])
		getupMinute := getupH*60 + getupM

		// 睡眠時間(分)
		if sleepMinute < getupMinute {
			// マイナス値になるので絶対値に変換
			minute += int(math.Abs(float64(sleepMinute - getupMinute)))
		} else {
			minute += getupMinute + dayMinute - sleepMinute
		}
	}
	return strconv.Itoa(minute)
}
0