LoginSignup
1
1

More than 3 years have passed since last update.

ABC049C - 白昼夢 / Daydream

Posted at

問題

https://atcoder.jp/contests/abs/tasks/arc065_a
スクリーンショット 2019-12-01 16.22.47.png

1回目

回答

str = gets.chomp
DREAM = "dream"
DREAMER = "dreamer"
ERASE = "erase"
ERASER = "eraser"

equal_flag = "NO"


while true
  str_size = str.size
  if str_size >= 5
    sliced_str = str.slice( ( str_size - 5 )..( str_size - 1 ) )
    if sliced_str == DREAM || sliced_str == ERASE
      if str == sliced_str
        equal_flag ="YES"
        break
      end
      str = str.slice( 0..( str_size - 6 ) )
      next
    end
  end
  if str_size >= 6
    sliced_str = str.slice( ( str_size - 6 )..( str_size - 1 ) )
    if sliced_str == ERASER
      if str == sliced_str
        equal_flag ="YES"
        break
      end
      str = str.slice( 0..( str_size - 7 ) )
      next
    end
  end
  if str_size >= 7
    sliced_str = str.slice( ( str_size - 7 )..( str_size - 1 ) )
    if sliced_str == DREAMER
      if str == sliced_str
        equal_flag ="YES"
        break
      end
      str = str.slice( 0..( str_size - 8 ) )
      next
    end
  end
  break
end

puts equal_flag

結果

スクリーンショット 2019-12-01 16.24.39.png

2回目

回答

S=gets.chomp
s = S.gsub("eraser","").gsub("erase","").gsub("dreamer","").gsub("dream","")
puts s.size==0?"YES":"NO"

結果

スクリーンショット 2019-12-01 16.24.58.png

感想

自分の知っている知識だけでも解けてしまうので他の人の回答がめっちゃ参考になる。
今回はパフォーマンスめちゃくちゃ影響したし、
実際の業務でこれに気付かなかったらこのパフォーマンスのままリリースされてしまっていたかと思うと怖い。
正規表現も今度触ってみよう。

1
1
0

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
1
1