結果
問題 |
No.113 宝探し
|
ユーザー |
|
提出日時 | 2018-03-14 19:51:07 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 754 bytes |
コンパイル時間 | 12,958 ms |
コンパイル使用メモリ | 223,852 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-16 21:50:12 |
合計ジャッジ時間 | 13,731 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
package main import ( "bufio" "fmt" "math" "os" ) // エントリポイント func main() { in := bufio.NewScanner(os.Stdin) // 地図に書かれた方角。NEWSのみ。 in.Scan() input1 := in.Text() fmt.Println(treasureHunt(input1)) } // 宝の位置までの最短の距離を返す。 func treasureHunt(direction string) string { // 0:NS, 1:EW dirCount := [2]int{} for _, c := range direction { switch string(c) { case "N": // 北 dirCount[0]++ case "S": //南 dirCount[0]-- case "E": // 東 dirCount[1]++ case "W": // 西 dirCount[1]-- } } // 南東(NE) ne := math.Pow(float64(dirCount[0]), 2) // 北西(SW) sw := math.Pow(float64(dirCount[1]), 2) return fmt.Sprintf("%f", math.Sqrt(ne+sw)) }