Day 6: Let’s Review
gets after chomp incase \n will leave in string
All variable should declare first!
String.split(”) to Array with each letter
ns = gets.to_i
ns.times do |n|
odd = []
even = []
xs = gets.to_s.chomp
xs.split(”).each_with_index do |x, index|
odd << x if index.odd?
even << x if index.even?
end
print “#{even.join} #{odd.join}\n”
end
gets after chomp incase \n will leave in string
All variable should declare first!
String.split(”) to Array with each letter
ns = gets.to_i
ns.times do |n|
odd = []
even = []
xs = gets.to_s.chomp
xs.split(”).each_with_index do |x, index|
odd << x if index.odd?
even << x if index.even?
end
print “#{even.join} #{odd.join}\n”
end
转载请注明:XAMPP中文组官网 » Day 6