結果

問題 No.113 宝探し
ユーザー dai11
提出日時 2017-08-04 09:27:46
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 579 bytes
コンパイル時間 1,151 ms
コンパイル使用メモリ 156,892 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-16 21:35:44
合計ジャッジ時間 1,883 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:12:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |   scanf("%s",S);
      |   ~~~~~^~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main(int argc, char **argv)
{
  char S[100]; //入力される文字列(N,E,W,S)
  int i;      //ループカウンタ
  int counter1 = 0; //移動した値
  int counter2 = 0; //移動した値
  
  scanf("%s",S);

  for(i = 0;i < strlen(S);i++)
  {
   
   if('S' == S[i])
   {
     counter1++;
   }
   
   else if('N' == S[i])
   {
     counter1--;
   }
   
   else if('E' == S[i])
   {
     counter2++;
   }
   
   else if('W' == S[i])
   {
     counter2--;
   }
  }
  printf("%f\n",hypot(counter1,counter2));

  return 0;
}
0