The fourth question of Java Group B of the 8th Blue Bridge Cup National Championship

Title: Small Calculator


Simulate a program calculator, input commands in sequence, the possible commands include


1. Number: 'NUM X', X is a string containing only uppercase letters and numbers, representing a current number
2 . Operation command: 'ADD','SUB','MUL','DIV','MOD', respectively means addition, subtraction, multiplication, division to take the quotient, division to take the remainder
3. Base conversion command: 'CHANGE K', will Convert the current base to K base (2≤K≤36)
4. Output command: 'EQUAL', output the result in current base
5. Reset command: 'CLEAR', clear the current number


The command is given according to the following rules:
Numbers, operation instructions will not be given continuously, and base conversion instructions, output instructions, and reset instructions may be continuously given
. The first number that appears after the operation instruction indicates the number involved in the operation. And between the operation instruction and the number, there will be no operation instruction and output instruction
. The first number that appears after the reset instruction indicates the basic value. And there will be no operation instruction and output instruction between the reset instruction and the first number. The
base conversion instruction may appear anywhere. During the


operation, the intermediate variable is a non-negative integer and less than 2^63.
Use uppercase 'A'~'Z' to represent 10~35


[Input format]
Line 1: 1 n, indicating the number of instructions
Line 2..n+1: One instruction is given per line. The instruction sequence must start with 'CLEAR' and satisfy the instruction rule


[output format]
to give each 'EQUAL' in turn






CHANGE 2
ADD
NUM 100000
CHANGE 8
EQUAL


[Sample output]
2040


resource convention:
peak memory consumption < 256M
CPU consumption < 1000ms




Please output strictly according to the requirements, and do not superfluously print redundant content like: "Please enter...".


All code is placed in the same source file, after debugging, copy and submit the source code.
Note: Do not use the package statement. Do not use features of jdk1.7 and above.
Note: The name of the main class must be: Main, otherwise it will be processed as invalid code.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326817230&siteId=291194637