Created
October 18, 2014 16:30
-
-
Save keiji-mu/933fe62fe71e07782717 to your computer and use it in GitHub Desktop.
CodeIQ 1097 中学入試から:正三角形?二等辺? 綴り間違ってた orz
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 | |
# coding: sjis | |
# CodeIQ q1097 中学入試から:正三角形?二等辺? | |
REGULAR = 'あ' | |
ISOSCELES = 'い' | |
OTHOER = 'う' | |
wa=[] | |
$<.each do |l| | |
# next unless l =~ /^T/ | |
id, prob, a0 = l.chomp.split /\t/ | |
v = []; e = [] | |
prob.split(/,/).each{|s| | |
v << $1.to_i if s =~ /角[ABC]=(\d+)度/ | |
e << $1.to_i if s =~ /[ABC]{2}=(\d+)cm/ | |
} | |
a1 = if v.size >= 2 # 頂点が2つ以上 .. 内角を比較 | |
a,b,c = v | |
c ||= 180 - a - b | |
a == b && b == c ? REGULAR : | |
a == b || b == c || c == a ? ISOSCELES : OTHOER | |
elsif e.size >= 3 # 辺が3つ .. 辺を比較 | |
a,b,c = e | |
a == b && b == c ? REGULAR : | |
a == b || b == c || c == a ? ISOSCELES : OTHOER | |
elsif e.size == 2 && e[0] == e[1] # 辺が2つで等しい .. 正三角形or二等辺 | |
v.size == 1 && v[0] == 60 ? REGULAR : ISOSCELES | |
# 辺が2つ頂点が1つでも決定できるが三角関数が必要なので「わからない」とする | |
# テストケース中には、この条件で正三角形や二等辺三角形は無かった | |
else | |
OTHOER | |
end | |
p [id,prob,a0,a1] if a0 != a1 | |
wa << id if a0 != a1 # IDを記録 | |
end | |
p wa.size | |
puts wa*',' # 答えの異なっているID出力 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment