2438. Useful Calculator

单点时限: 3.0 sec

内存限制: 256 MB

We want to make a useful calculator. So we decided to make a calculator with the following functions.

CommandUsageEffect
++ arg1This command adds the arg1 to the current value. The arg1 must be a non negative integer. You can use the "restore" command instead of the arg1.
-- arg1This command subtracts the arg1 from the current value. The arg1 must be a non negative integer. You can use the "restore" command instead of the arg1.
** arg1This command multiplies the current value by the arg1. The arg1 must be an integer. You can use the "restore" command instead of the arg1.
// arg1This command divides the current value by the arg1. The surplus should be ignored. The arg1 must be a non zero integer. You can use the "restore" command instead of the arg1.
%% arg1This command calculates the surplus which divides the current value by the arg1. The arg1 must be a positive integer and current value must be a non negative integer. You can use the "restore" command instead of the arg1.
memorymemoryThis command memorizes the current value. The value memorized before should be deleted.
restorefunction restoreThis command reads the current memorized value. The function should be either of "+" , "-" , "*" , "/" , "%".
printprint arg1This command outputs the current value. The arg1 shows the cardinal number. The arg1 should be either of "-b", "-o" , "-d" , "-h". The "-b" means output should be a binary number. The "-o" means output should be an octal numeral. The "-d" means output should be a decimal number. The "-h" means output should be a hexadecimal number. Characters used in the representation are follows: Digits '0'-'9' to denote 0-9, lower-case letters 'a'-'f' denote 10-15. For example decimal 62 should be denoted by hexadecimal "3e" and decimal -62 should be denoted by hexadecimal "-3e".

Your task is to make this calculator. You can assume that initial value is 0 and initial memorized value is 0. You should ignore the invalid command.

输入格式

Input consists from multiple test cases. The first line of each test case contains single positive integer n. Following n lines contain a command. A single line containing 0 denotes the end of input.

You can assume that given command should be correct about usage. You can also assume that an input and a calculation result must be fit in 64 bit signed integer.

输出格式

For each test case, you are to print “Case X:” where X is the number of the test case starting with 1 for the first test case and incrementing by 1 for successive test case. For each print command, you should output a current value by specified cardinal number. You should output a blank line between two test cases.

样例

Input
6
+ 3
- 1
memory
* 2
/ restore
print -d
0
Output
Case 1:
2

2 人解决,9 人已尝试。

2 份提交通过,共有 54 份提交。

9.7 EMB 奖励。

创建: 15 年,4 月前.

修改: 6 年,8 月前.

最后提交: 3 年,5 月前.

来源: ECNU 选拔 2008

题目标签