Project1

标题: Simple Calculator(Ruby) [打印本页]

作者: david50407    时间: 2011-7-31 11:17
标题: Simple Calculator(Ruby)
本帖最后由 忧雪の伤 于 2011-7-31 12:46 编辑

Prologue

One day, Ruby picked up a calculator on the ground. But she isn't sure whether it is broken or not. She wants to test the calculator, but she doesn't want to calculate by herself. So, can you help her to calculate the right answer?




Question

Ruby will give you the question to test the calculator. And you must to receive her the correct answer. (The question only have numbers and `+' `-' `*' `/' these four operations)




Input Rule

First you will get a number N.And next N lines will be the question.
The question must be a normal math expression like "1+2+46/5", you only have to remenber the rule of math.
There must have zero or more whitespaces between the operations and numbers.
(There's no float number, only integer)




Output Rule

For each questions, you must output a new line and the answer to the question.




Need Skills

Standard I/O,
if/else statement,
Some simple operations.




序幕

某天 Ruby 在地上捡到了一个计算器。但是她不确定这台计算器是好是坏,所以想来测试它。但是 Ruby 又不想自己动手算数字,所以你能帮助他一下吗?



问题

Ruby 会给你几个用来测试计算器的算式,然后你必须要给她正确的答案。(算式里只会出现数字与四则运算符)



输入规则

首先会有一个数字 n ,紧接着N行都是一个算式。值得注意的是,运算符与数字之间可能会有 0 个或以上的空格。(只会有整数运算不会出现小数点。)



输出规则

對於每個算式輸出一行結果。



所需技能

标准输出入;
if,else 判断;
一些简单的运算符。




line display
作者: DeathKing    时间: 2011-7-31 11:30
本帖最后由 DeathKing 于 2011-7-31 20:28 编辑
  1. # Simple Calculator
  2. # by: ditro

  3. gets.chomp.to_i.times { puts(eval(gets.chomp)) }

复制代码
缺点:精度不高;
短评:越来越囧了??




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1