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?

Paiza D310:タイトルの略称 Rubyで

Posted at

apple
book
cake

という入力を受け取り、

abc

という出力を行う際のコード

# 標準入力から単語を読み込み、最初の文字を連結する
result = []

while line = gets
  result << line[0]  # 各行の最初の文字を取得
end

puts result.join  # 結果を出力

配列を宣言、ループ処理で入力を受け取り変数lineに代入、
result<<line[0]にて、配列に受け取ったlineの初めの1文字を取得し、
joinメソッドを使って各配列を連結。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?