Last active
January 12, 2016 11:30
-
-
Save torazuka/a737b067c00fb0afa97f to your computer and use it in GitHub Desktop.
オフラインリアルタイムどう書く#参考問題01 Ruby解答
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
def is_fourcards (cs) | |
return cs.has_value?(4) | |
end | |
def is_threecards (cs) | |
return cs.has_value?(3) | |
end | |
def cnt_pairs (cs) | |
return cs.select {|k,v| v == 2}.length | |
end | |
input = ARGV[0] | |
ws = input.gsub(/10/,"T").split("") | |
cs = [] | |
ws.each { |w| cs.push(w) unless /S|H|D|C/ =~ w } | |
nums = { } | |
(2..9).each { |n| | |
nums[n.to_s] = 0 | |
} | |
nums.update({"T" => 0, "J" => 0, "Q" => 0, "K" => 0, "A" => 0}) | |
cs.each { |c| | |
nums[c] = nums[c] + 1 | |
} | |
result = "--" | |
if is_fourcards(nums) then | |
rsult = "4K" | |
elsif is_threecards(nums) && cnt_pairs(nums) == 1 then | |
result = "FH" | |
elsif is_threecards(nums) then | |
result = "3K" | |
elsif cnt_pairs(nums) == 2 then | |
result = "2P" | |
elsif cnt_pairs(nums) == 1 then | |
result = "1P" | |
end | |
print result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
問題はこちら。
http://qiita.com/Nabetani/items/cbc3af152ee3f50a822f