ruby

AOJ 0169 - Blackjack

while s = gets.chomp break if s == "0" res = 0 one_n = 0 s.split(" ").map{|e| e.to_i }.each{|e| if e == 1 then one_n += 1 elsif e >= 10 && e <= 13 res += 10 else res += e end } f = false for i in 0..one_n #i: 1をそのまま使う数 if res + i +…

AOJ 0065 - Trading

Ruby便利*1 last_m = {} this_m = {} while s = gets break if s == "\n" data = s.split(",").map{|e| e.to_i } last_m[data[0]] = 0 unless last_m.key?(data[0]) last_m[data[0]] += 1 end while s = gets break if s == nil data = s.split(",").map{|e|…

AOJ 0084 - Search Engine

重複した文字列は除かなくてよかった. words = gets.delete(",.").split(" ").select{|word| 3 <= word.size && word.size <= 6 } print words[0] for i in 1..words.size-1 print " #{words[i]}" end puts ""

gets[0..-2]は怖い

gets[0..-2]で改行を削除したと思っていたら,ファイル末尾に改行が含まれていないときに死にますね. chompをつかって生きたいと思います.

AOJ 0087 - Strange Mathematical Expression

処理するのが面倒な問題ですね.Rubyさんで解きました. C++さんでも解けるようにしたいです. def plus(stack) a = stack.pop b = stack.pop stack.push(b+a) end def minus(stack) a = stack.pop b = stack.pop stack.push(b-a) end def times(stack) a = …

AOJ 0038 - Poker Hand

いまいちのコードのきれいさ def straight?(cards) _cards = cards.dup _cards[0] += 13 if _cards[0] == 1 && _cards[1] == 10#1,10,?,?,?だったら14,10,11,12,13に絞って良い _cards.sort! #再ソート f = true for i in 1..4 #1,2,3,4,5などの連番判定 f =…