カンマ区切りの3つのデータの入力 (paizaランク D 相当)
自分の解答
practice_01.rb
inputs = gets.chomp.split(",")
inputs.each do |input|
puts input
end
入力を受け取ると同時にカンマ区切りで変数に格納し、eachメソッドで出力する。
ChatGPTの解答
以下は、問題を解決するためのRubyプログラムの例です。
ruby
# 入力を受け取る
input_str = gets.chomp
# カンマで分割して各文字列を取得
strings = input_str.split(',')
# 順に3行で出力
strings.each do |str|
puts str
end
このプログラムは、標準入力から1行の文字列を受け取り、カンマで分割して配列に格納します。そして、その配列を順に取り出して各文字列を3行で出力します。