結果

問題 No.113 宝探し
ユーザー togaerror
提出日時 2015-04-01 15:21:04
言語 Perl
(5.40.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 505 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 5,760 KB
実行使用メモリ 6,016 KB
最終ジャッジ日時 2024-11-16 20:42:24
合計ジャッジ時間 1,232 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

#!/usr/bin/perl

use strict;
use warnings;


my $str = <>;
chomp $str;
my @array = split //, $str;

my ($n, $e, $w, $s) = (0, 0, 0, 0);

for(my $i = 0; $i < length $str; $i++) {
	if ($array[$i] eq 'N') {
		$n++;
	} elsif($array[$i] eq 'E') {
		$e++;
	} elsif ($array[$i] eq 'W') {
		$w++;
	} elsif($array[$i] eq 'S') {
		$s++;
	}
	
}

$n -= $s;
$e -= $w;

$n *= $n;
$e *= $e;

my $ans = $n + $e;
$ans = sqrt $ans;
$ans += 0.000005;
$ans *= 100000;
$ans = int $ans;
$ans /= 100000;

print "$ans\n";

exit;
0