编程介的小学生 2017-08-30 06:37 采纳率: 20.5%
浏览 872
已采纳

Nullary Computer

Brian Huck has invented a new power saving
computer. With the current CMOSbased processors, a certain amount of power is lost each time a bit is changed from 0 to 1 or back. To avoid this problem, Brian��s new Nullary Core stores only zeros. All numbers are stored in nullary form, as shown on the right.
His initial 64-nit model has 26 registers, each of which may store up to 64 nits, and any attempt to store more than 64 nits will result in a run time error. There is also a flag register, which contains either a zero, or nothing. The instruction set is as follows:

Table 1NC Instruction Set
Instruction
Explanation and how to simulate in C
A
Add a zero to the value in register A (similarly for alluppercase letters).
a++;
a
First, empty the flag register. Then, if possible, remove a zero from register A, and place it in the flag register(similarly for all lowercase letters)
flag = 0; if(a>0) { flag=1; a--; }
(
If the flag register is empty, jump past the matching ).Otherwise, empty the flag register.
while(flag) { flag=0; ....
)
Jump to the matching (.
... }
Apart from instructions, no other characters than whitespace are allowed in a nullary program.

Sample programs

Brian has provided some programs to illustrate the elegance and simplicity of his computer.
Your task will be to write a sorting program for Brian��s Nullary Corebased Prototype Computer. The NCPC has limited memory, so your program must be no longer than 5432 instructions. Also, the running time of your program must be no more than 5 �� 106 steps for any possible input, where a step is considered to be the execution of one instruction.

b(b)a(Ba)
Move register A to register B (by first emptying register B, then repeatedly pulling a single zero from register A and placing it into B).
XXXa(GIa)i(g(FYg)y(Gy)f(Zb(z)z(i(YBi)y(Iy))f)Zb(zb)z(xz)i)x
Set the flag register if the number of zeros in register A is prime.

Important note: You must submit the nullary source code of this
program, and not some Java, C or C++ source code.

Input
The numbers to be sorted will be given in the first 24 registers A-X; the remaining two registers (Y and Z) will be empty.

Output

     The sorted numbers should be in registers A through X, in increasing order.

Register Y and Z should be empty.

Sample Input

A 0
B 000000000
C 000000
D 0000
E 00000000
F 0000000
G 0000
H 000000
I 000000000
J 000
K

L

M

N

O

P

Q

R

S
T
U
V
W
X 0
Y
Z

Sample Output

A
B
C
D
E
F
G
H
I
J
K

L

M

N 0
O 0
P 000
Q 0000
R 0000
S 000000
T 000000
U 0000000
V 00000000
W 000000000
X 000000000
Y
Z

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-09-14 15:49
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Excel发现不可读取的内容
  • ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。