4th. Since I solved the C problem last time, I licked it that I could do it this time, and I stumbled upon the basics of computer engineering.
abc169a.rb
ab = gets.chomp.split(" ").map!{|item| item.to_i}
puts ab[0] * ab[1]
Just write.
abc169b.rb
n = gets.chomp.to_i
a = gets.chomp.split(" ").map!{|item| item.to_i}
num = 1
ans = 1
th = 10**18
a.sort!{|a,b| (-1)*(a <=> b)}
if a[n - 1] == 0
puts 0
exit
end
for num in 1..n do
ans = ans * a[num-1]
num = num + 1
if ans > th
puts "-1"
exit
end
end
puts ans
It's an integer multiplication, but in order
abc169c.rb
ab = gets.chomp.split(" ")
a=ab[0].to_i
b=((ab[1].to_s).delete(".")).to_i
ans = a*b/100
puts ans
Multiply b by 100, calculate it as an integer with to_s, and divide it by 100. When I did it, I stepped on the pattern of repeating decimals in binary notation. Treat b as an integer and to_s is easy after removing the decimal point. I can't pass this either. I will devote myself.
Recommended Posts