此题属于比较麻烦的模拟题,比赛的时候是队友写的, 比赛结束之后自己也写了一遍,感觉对复杂模拟的掌控还是不行!
解析:
我感觉 ADD操作 和 MOV操作比较类似 所以就写在了一块,MUL操作单独写就行了。
#include<stdio.h>
#include<string.h>
#define maxn 100 long long cpu[][]; int Binary(char str[])
{
int i, sum = ;
for(i=; str[i]; i++)
sum = sum* + str[i]-''; return sum;
} int GetR()
{
int i, len, R;
char str[maxn]; scanf("%s", str); len = strlen(str)-; if(str[] >= 'A' && str[] <= 'D')
{
if(str[] == 'H')
R = cpu[str[]-'A'][];
else if(str[] == 'L')
R = cpu[str[]-'A'][];
else if(str[] == 'X')
R = cpu[str[]-'A'][];
} else if(str[len] == 'H')
{
str[len] = ;
sscanf(str+,"%X", &R);
} else if(str[len] == 'B')
{
str[len] = ;
R = Binary(str+);
}
else
{
sscanf(str+,"%d", &R);
} return R;
} void MOV_ADD(int m,int n,int flag)
{
int R; R = GetR(); if(flag == )
{
cpu[m][n] = R;
}
else
{
cpu[m][n] += R;
} if(n == )
{
cpu[m][] = cpu[m][]/;
cpu[m][] = cpu[m][]%;
}
else
cpu[m][] = cpu[m][]* + cpu[m][];
} void MUL(int m,int n)
{ if(n == || n == )
{
cpu[][] = cpu[m][n]*cpu[][];
}
else
{
cpu[][] = (cpu[m][n]*cpu[][])/;
cpu[][] = (cpu[m][n]*cpu[][])%; cpu[][] = cpu[][]/;
cpu[][] = cpu[][]%;
}
cpu[][] = cpu[][]/;
cpu[][] = cpu[][]%;
} int main()
{
int T, t, k, x;
char str[maxn], str2[maxn];
scanf("%d",&T); while(T--)
{ scanf("%d",&t);
memset(cpu, , sizeof(cpu));
while(t--)
{
scanf("%s%2s", str,str2); k = str2[] - 'A'; if(str2[] == 'X')
x = ;
else if(str2[] == 'H')
x = ;
else if(str2[] == 'L')
x = ; if(strcmp(str,"MOV") == )
{
MOV_ADD(k,x,);
}
else if(strcmp(str,"ADD") == )
{
MOV_ADD(k,x,);
}
else
MUL(k,x);
}
printf("%lld %lld %lld %lld\n",cpu[][], cpu[][], cpu[][], cpu[][]);
}
return ;
}