結果

問題 No.113 宝探し
ユーザー ayaaya
提出日時 2019-07-30 15:33:19
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 1,587 bytes
コンパイル時間 672 ms
コンパイル使用メモリ 18,496 KB
実行使用メモリ 18,772 KB
最終ジャッジ日時 2023-09-18 02:04:46
合計ジャッジ時間 2,711 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

宝探し
問題文
A君は宝の地図を手に入れました。
地図には公園があり公園の中心に目印が書いてありました。
そして、そこからの移動方法が書いてありました。
書いてある文字に対応する移動方法は次のようになります。

・「N」は北に1メートル移動する。
・「E」は東に1メートル移動する。
・「W」は西に1メートル移動する。
・「S」は南に1メートル移動する。

例えば、「NE」と書いてあるなら北に1メートル歩いたのち東に1メートル歩きます。
その地点を掘れば宝が出てくるようです。
しかし、A君は移動方法の無駄に気づきました。
「NE」であれば北東の方向に12+12−−−−−−√=2–√メートルだけ移動すれば良さそうです。
A君は公園の中心から最短の距離で宝が埋まっている位置に移動したいです。
障害物にぶつかる可能性は無いとして、A君は何メートル移動する必要があるでしょうか?

入力
S
地図に書かれた文字列Sが1行で与えられる。
文字列Sの長さは1文字以上100文字以内である。
文字列は'N','E','W','S'の4文字のみから構成される。


*/

$input=str_split(trim(fgets(STDIN)));
$x=0;
$y=0;
foreach($input as $value){
  switch($value){
    case "N":
      $y++;
      break;
    case "S":
      $y--;
      break;
    case "E":
      $x++;
      break;
    case "W":
      $x--;
      break;
  }
}
echo round(sqrt(($x*$x)+($y*$y)),5);
?>
0