結果

問題 No.48 ロボットの操縦
ユーザー yo-kondoyo-kondo
提出日時 2018-03-10 19:24:42
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,096 bytes
コンパイル時間 11,719 ms
コンパイル使用メモリ 228,060 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 18:23:39
合計ジャッジ時間 12,467 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 WA -
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 WA -
testcase_23 AC 1 ms
5,376 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

// エントリポイント
func main() {
	in := bufio.NewScanner(os.Stdin)
	// 移動先の東西軸座標
	in.Scan()
	input1 := in.Text()
	// 移動先の南北軸座標
	in.Scan()
	input2 := in.Text()
	// ロボットが1命令につき前進することができる最大の距離
	in.Scan()
	input3 := in.Text()

	fmt.Println(maneuver(input1, input2, input3))
}

// 何回命令すれば目的地に到着できるか計算する。
func maneuver(eastWest string, northSouth string, distance string) string {
	e, _ := strconv.Atoi(eastWest)
	n, _ := strconv.Atoi(northSouth)
	d, _ := strconv.Atoi(distance)
	orderCount := 0

	if n < 0 {
		// 最初は北を向いているため南に向かうには方向転換が必要
		orderCount += 2
	}
	orderCount += int(math.Ceil(math.Abs(float64(n) / float64(d))))

	if e != 0{
		// 方向転換。北南どちらを向いていても1かいで東西へ向く。
		orderCount++
		orderCount += int(math.Ceil(math.Abs(float64(e) / float64(d))))
	}
	return strconv.Itoa(orderCount)
}
0