defjudge(a,b,c) if a == b && b == c && a != 's' return a else returnnil end end
while gets s = $_.chomp.chars res = nil 0.upto(3) do|i| res = judge(s[i], s[i+3], s[i+6]) breakif res res = judge(s[3*i], s[3*i+1], s[3*i+2]) breakif res end if s[4] != 's'and (judge(s[0], s[4], s[8]) or judge(s[2], s[4], s[6])) puts s[4] elsif res.nil? puts 'd' else puts res end end
😀 Pythonコード
defjudge(a, b, c): return a if a == b == c and a != 's'else0
whileTrue: try: s = raw_input() for i in range(3): result = judge(*s[i:9:3]) if result: break result = judge(*s[3*i:3*i+3]) if result: break else: result = s[4] if s[4] != 's'and (judge(*s[0:9:4]) or judge(*s[2:7:2])) else'd' except: break print result