Record do arithmetic problem stepped pit

First directly attached to the original question:

Problem Description

  Simulation calculator program, are sequentially input command, there are commands may contain


  1. Digital: 'NUM X', X is a alphanumeric and contains only a character string, this represents a hexadecimal
  2. The operation instructions: ' ADD ',' SUB ',' MUL ',' DIV ',' MOD ', respectively, subtraction, multiplication, division takes provider, division modulo
  3. the binary conversion instruction:' CHANGE K ', the current is converted to hexadecimal K-band (2≤K≤36)
  4. output instruction: 'EQUAL', the current binary output
  5. reset command: 'CLEAR', clear current


  instruction is given according to the following rules:
  figures, operation instruction not continuously given binary conversion command, the output command, it is possible to continuously reset instruction given
  operation instruction after the first number, represents a number involved in computing. Without producing output command execution instruction and the operation instruction and the digital intermediate
  the first number after the reset instruction, it represents the base value. And the output command execution instruction and reset instruction and do not appear in the first intermediate digital
  binary conversion instructions may appear anywhere in the


  calculation process the intermediate variables are non-negative integers, and less than 2 ^ 63.
  With a capital 'A' ~ 'Z' represents 10 to 35

Input Format

  Line 1: 1 n, the number of instructions
  a first 2..n + 1 rows: an instruction is given for each row. A certain sequence of instructions to 'CLEAR' as a start, and satisfying instruction rule

Output Format

  The results are given in sequence 'EQUAL' obtained each time

Sample input

7
CLEAR
NUM 1024
CHANGE 2
ADD
NUM 100000
CHANGE 8
EQUAL

Sample Output

2040

1, CLEAR binary retention after the current settings, clear numbers only.

2, any decimal binary in turn, need to be considered passed in value is zero, if negative, and converted digital ascill with code 0 0 ascill text code is not the same need to c = c + '0'; (c: digit integer).

3, when the search text with the string.find (xx)! = String.npos cause logic errors, write, the value in the NUM input, such as 36 hex, as long as the input text containing the operator, ADD, SUB, MUL, DIV, MOD these values ​​when there will be a logical error, but did not perform the operation to set operation mode. Ah stupid, before writing the project is to determine the basic text keyword results, no so accurate, the results of today this bad habit manifests itself, correct. . . Correct posture should be the first to find a space, and then split the text first, and then determine the appropriate action left keywords, rather than directly string.find. 

Published 18 original articles · won praise 8 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_20408397/article/details/83684460