LoginSignup
0
0

More than 1 year has passed since last update.

Atcoder の「上書き」問題をRubyで解く

Last updated at Posted at 2022-05-01
# https://atcoder.jp/contests/past202012-open/tasks/past202012_b

# 標準入力の1行目に文字列の長さが与えられる
length = gets.chomp

# 標準入力の二行目にテキストが与えられる
text = gets.chomp

# テキストを1文字単位で配列にしてループする
text.chars.each do |alphabet|
  # テキストからアルファベットを削除
  text.delete! alphabet
  # テキスト末尾にアルファベットを追加
  text += alphabet
end

puts text

問題

英小文字からなる長さ N の文字列 S が与えられます。
また、文字列 T があり、 T ははじめ空文字列です。

あなたは以下の操作を i=1,2,…,N に対して、 i=1 から順に行います。

S の左から i 番目の文字を c とする。 T から c と同じ文字を全て削除した後、 T の末尾に c を追加する。
操作が終わった後の T を求めてください。

image.png

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

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