This question belongs to the more troublesome simulation question, the match time is the teammate writes, after the race finishes oneself also wrote once, feels to the complex simulation control still not to be possible!
Analytical:
I feel that the add operation and the Mov operation is similar, so it is written in a piece, mul operation alone to write the line.
#include <stdio.h>#include<string.h>#defineMAXN 100Long Longcpu[4][3];intBinary (Charstr[]) { intI, sum =0; for(i=0; Str[i]; i++) Sum= sum*2+ str[i]-'0'; returnsum;}intGetr () {intI, Len, R; CharSTR[MAXN]; scanf ("%s", str); Len= strlen (str)-1; if(str[1] >='A'&& str[1] <='D') { if(str[2] =='H') R= cpu[str[1]-'A'][1]; Else if(str[2] =='L') R= cpu[str[1]-'A'][2]; Else if(str[2] =='X') R= cpu[str[1]-'A'][0]; } Else if(Str[len] = ='H') {Str[len]=0; SSCANF (str+1,"%x", &R); } Else if(Str[len] = ='B') {Str[len]=0; R= Binary (str+1); } Else{sscanf (str+1,"%d", &R); } returnR;}voidMov_add (intMintNintflag) { intR; R=Getr (); if(Flag = =0) {Cpu[m][n]=R; } Else{Cpu[m][n]+=R; } if(n = =0) {cpu[m][1] = cpu[m][0]/ the; cpu[m][2] = cpu[m][0]% the; } Elsecpu[m][0] = cpu[m][1]* the+ cpu[m][2];}voidMUL (intMintN) { if(n = =2|| n = =1) {cpu[0][0] = cpu[m][n]*cpu[0][2]; } Else{cpu[3][0] = (cpu[m][n]*cpu[0][0])/65536; cpu[0][0] = (cpu[m][n]*cpu[0][0])%65536; cpu[3][1] = cpu[3][0]/ the; cpu[3][2] = cpu[3][0]% the; } cpu[0][1] = cpu[0][0]/ the; cpu[0][2] = cpu[0][0]% the;}intMain () {intT, T, K, X; CharSTR[MAXN], STR2[MAXN]; scanf ("%d",&T); while(t--) {scanf ("%d",&t); memset (CPU,0,sizeof(CPU)); while(t--) {scanf ("%s%2s", STR,STR2); K= str2[0] -'A'; if(str2[1] =='X') x=0; Else if(str2[1] =='H') x=1; Else if(str2[1] =='L') x=2; if(strcmp (str,"MOV") ==0) {Mov_add (k,x,0); } Else if(strcmp (str,"ADD") ==0) {Mov_add (k,x,1); } ElseMUL (k,x); } printf ("%lld%lld%lld%lld\n", cpu[0][0], cpu[1][0], cpu[2][0], cpu[3][0]); } return 0;}
(2015 Zhengzhou Institute of Light Industry ACM School title) E Assembly principle