ちくわ

ちくわにきゅうりを入れるとうまい

AtCoder ABC #036 の A 「お茶」をやってみた

これやりました。

abc036.contest.atcoder.jp

結果

1 回目

  • Runtime Error で失敗

http://abc036.contest.atcoder.jp/submissions/723830

標準入力で渡すということをコマンド引数にしていた

2 回目

  • Score 50
  • Wrong Anser

http://abc036.contest.atcoder.jp/submissions/723834

切り上を考慮してなかった

3 回目

  • Score 100

http://abc036.contest.atcoder.jp/submissions/723836

有識者にレビューしてもらったポイント

レビューしてもらったのは最後に Score100 だったコード

  • Stdin = gets.split(" ")
    • Stdin は組込変数だから言葉を変えたほうが良さそう
  • 切り上はそういうメソッド ceil があるよ
  • test を意識するならば、def 内は ans を返すだけにして、戻り値でジャッジ出来るようにしとくと吉

その他、ここまで作るに辺り、遭遇したエラー達

formal argument cannot be a constant

$ ruby /tmp/dc.ruby 1 2
/tmp/dc.ruby:4: formal argument cannot be a constant
def count(PB, Case)
            ^
/tmp/dc.ruby:4: formal argument cannot be a constant
def count(PB, Case)

def 内は local 変数のため、小文字または _ で始める必要がある
http://docs.ruby-lang.org/ja/2.0.0/doc/spec=2fvariables.html#local
ちなみに PB はペットボトルのつもりだった

syntax error, unexpected keyword_case

$ ruby /tmp/dc.ruby 1 2
/tmp/dc.ruby:4: syntax error, unexpected keyword_case
def countPB(pb, case)
                    ^
/tmp/dc.ruby:6: syntax error, unexpected keyword_end, expecting keyword_when

case は予約後で使えなかった。 ペットボトルの箱を入れ物の意味でケース (case) にしてしまった...

http://docs.ruby-lang.org/ja/2.0.0/doc/spec=2flexical.html#reserved

syntax error, unexpected ',', expecting ')'

$ ruby /tmp/dc.ruby 1 2
/tmp/dc.ruby:5: syntax error, unexpected ',', expecting ')'
  puts (pb, pb_case)
           ^
/tmp/dc.ruby:8: syntax error, unexpected $end, expecting keyword_end

puts のあとに空白入れたらダメです

comparison of String with 1 failed (ArgumentError)

$ ruby /tmp/dc.ruby 1 2
/tmp/dc.ruby:4:in `>=': comparison of String with 1 failed (ArgumentError)
    from /tmp/dc.ruby:4:in `<main>'

数字じゃないから演算子 > とかで比較できない 標準入力された数値を .to_i で integer に変換した