0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

第18回オフラインリアルタイムどう書くの参考問題をRubyで解く

Posted at

問題はこちら。
http://nabetani.sakura.ne.jp/hena/ord18mafovafo/

def solve(q)
  h1 = {'L'=>'V','J'=>'V','Z'=>'mV','U'=>'VV','S'=>'Vm'}
  h2 = {'L'=>'m','J'=>'m','Z'=>'mV','U'=>'mm','S'=>'Vm'}
  folds = ''
  isLeft = true
  q.chars.each{|c|
    fw = (isLeft ? h1 :  h2)[c]
    folds.chars.each_with_index{|fold, i|
      fw += fold
      if ((isLeft and i.odd?) or (!isLeft and i.even?))
        fw += h1[c]
      else
        fw += h2[c]
      end
    }
    folds = fw
    case c
    when 'L'
      isLeft = false if isLeft
    when 'J'
      isLeft = true unless isLeft
    when 'U'
      isLeft = !isLeft
    end
  }
  folds
end

DATA.readlines.each do |line|
  no,q,a = line.chop.split(/\s+/)
  ans = solve(q)
  print no + "\t" + ans
  puts ans == a ? ' o' : ' x'
# break
end
__END__
0	JZ	mVVmV
1	J	V
2	L	V
3	Z	mV
4	U	VV
5	S	Vm
6	JL	VVm
7	JS	VmVVm
8	JU	VVVmm
9	LU	mmVVV
10	SL	VVmmV
11	SS	VmVVmmVm
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?