Created
February 16, 2014 17:49
-
-
Save Shinpeim/9037973 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Solver | |
def initialize(open_char, close_char) | |
@open_char = open_char | |
@close_char = close_char | |
@count = 0 | |
end | |
def run(string) | |
chars = string.split("") | |
chars.each do |char| | |
case char | |
when @open_char | |
open | |
when @close_char | |
close | |
else | |
raise "invalid charactor detected" | |
end | |
end | |
if @count == 0 | |
p "対応がとれている" | |
else | |
p "対応がとれていない" | |
end | |
end | |
def open | |
@count += 1 | |
end | |
def close | |
@count -= 1 | |
if @count < 0 | |
raise "invalid format" | |
end | |
end | |
end | |
Solver.new("「", "」").run("「」「「「」「」」「」「「「」」「」「「「」」「」」「「」「「」」「「」「「」」」「「」「「」「「「」」「」」」」」」」") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment