結果

問題 No.113 宝探し
ユーザー TD
提出日時 2022-06-02 14:28:57
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 1,101 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 104,064 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-09-21 01:56:45
合計ジャッジ時間 2,361 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

namespace yukicoder
{
    class Program
    {
        static void Main(string[] args)
        {

            string s = Console.ReadLine();
            int[] b = new int[4];
            double c=0;
            double d = 0;
 
            double ans = 0;
            for(int i = 0; i <s.Length; i++)
            {
               string  a = s.Substring(i,1);
                if (a == "N")
                {
                    b[0]++;
                }else if (a == "E")
                {
                    b[1]++;
                }else if (a == "W")
                {
                    b[2]++;
                }else
                {
                    b[3]++;
                }
            }
            c = b[0] - b[3];
            d = b[2] - b[1];
            if (c < 0)
            {
                c *= -1;
            }
            if (d < 0)
            {
                d *= -1;
            }
            c=Math.Pow(c, 2);
            d = Math.Pow(d, 2);
            ans = Math.Sqrt(c + d) ;
            
            Console.WriteLine(ans);
            
        }
    }
}
0