LoginSignup
0
0

More than 5 years have passed since last update.

AizuOnlineJudgeを始めてみる

Last updated at Posted at 2018-11-13

プログラムの勉強のために課題を探している人のための入門記事。

初心者向けのつまりそうなとこだけ補足してます。

AOJとは

https://onlinejudge.u-aizu.ac.jp/courses/list
様々なプログラム課題が用意されており、多数の言語で課題の回答を提出、回答を判断してくれるサイトです。
最初は難易度低いですが、速度やメモリ制限などもあるので難しい課題はかなり頭を使いそう(まだあんまりやってない)。

課題提出の注意

Inputの受け取り方

問題文には記載していないのですが、AOJのInputは標準入力から受け取るようです。
言語によって多少受け取り方が異なるので受け取り方法をメモしておきます。

JavaScript

let x = require('fs').readFileSync('/dev/stdin', 'UTF-8');

※ /dev/stdinはLinuxなどで使われる標準入力にアクセスするためのデバイス

Python

x = input()

補足

そもそも標準入力とは何か

プログラムを動作させるためには入力を受け取らなければならないことがあります。
入力の受け取り方としては、以下のようなものがあります。

  • 引数で渡す
  • 標準入力で渡す
  • プログラム内でファイル/DBなどの外部情報を読み込む
  • APIコール時のget, postパラメータ

ざっくり言うと標準入力とは、数ある情報の受け取り方の1つです。

引数で入力を受け取る方法のサンプル(JS)

input_arg.js
for(var i=0; i<process.argv.length; i++){
    console.log("argv[" + i + "] = " + process.argv[i]);
}
$ node input_arg.js arg1 arg2
argv[0] = /home/foobar/.nodebrew/node/v6.10.2/bin/node
argv[1] = /home/foobar/work/wk_20181106_175738/input_arg.js
argv[2] = arg1
argv[3] = arg2

標準入力で受け取る方法のサンプル(JS)

input_stdin.js
let x = require('fs').readFileSync('/dev/stdin', 'UTF-8');
console.log("stdin: " + x);
$ echo "foobar" | node input_stdin.js
stdin: foobar
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0