iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 3
0

嗨,我是 Fly,用 Ruby 寫 Chatbot 並挑戰30天分享心得
為確保不會沒靈感
每日含 Ruby 解題增加內容
https://www.hackerrank.com/domains/tutorials/30-days-of-code

Day 2: Operators

  • ARGF.readline 可用gets
  • 沒有印結果就不會有結果,拜託
  • 取 round 就是四捨五入

stringio 可作輸出用

require 'stringio'

io = StringIO.new
io.puts "Hello World"
io.string #=> "Hello World\n"

#!/bin/ruby

require 'json'
require 'stringio'

# Complete the solve function below.
def solve(meal_cost, tip_percent, tax_percent)
    (meal_cost*(100+tip_percent+tax_percent)/100).round
end

meal_cost = ARGF.readline.to_f

tip_percent = ARGF.readline.to_i

tax_percent = ARGF.readline.to_i

p solve meal_cost, tip_percent, tax_percent

上一篇
Day 2
下一篇
Day 4
系列文
懶人寫寫 BOT30

尚未有邦友留言

立即登入留言