设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1923|回复: 1
打印 上一主题 下一主题

[question] Simple Calculator(Ruby)

[复制链接]
梦石
0
星屑
50
在线时间
462 小时
注册时间
2007-7-30
帖子
643
跳转到指定楼层
1
发表于 2011-7-31 11:17:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 忧雪の伤 于 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
RGE这万年大坑 啥时填起来@@

梦石
0
星屑
1045
在线时间
1564 小时
注册时间
2008-7-30
帖子
4418

贵宾

2
发表于 2011-7-31 11:30:43 | 只看该作者
本帖最后由 DeathKing 于 2011-7-31 20:28 编辑
  1. # Simple Calculator
  2. # by: ditro

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

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

点评

你说的……  发表于 2011-7-31 20:26
我沒說不能xD  发表于 2011-7-31 20:24
总不能让我读一行输出一行呗?  发表于 2011-7-31 13:19
對了 這是基本題 不要那麼快就雷  发表于 2011-7-31 11:46
Nice 還有更短的xD  发表于 2011-7-31 11:45

See FScript Here:https://github.com/DeathKing/fscript
潜心编写URG3中。
所有对URG3的疑问和勘误或者建议,请移步至发布页面。
欢迎萌妹纸催更
回复 支持 反对

使用道具 举报

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-25 03:55

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表