简单的模拟,读懂了题就会做了
#include <stdio.h>
char hax[17]="0123456789ABCDEF";
char ans[256];
int main()
{
char a, b;
while (1)
{
int i;
for ( i = 0 ; i < 256 ; i++ )
{
if( EOF == scanf("%c", ans+i) ) return 0;
ans[i]-=( ans[i] > '9' ? 55 : 48 );
}
getchar();
if ( ans[0] == 8 ) break;
int num = 0, flag= 1;
char t;
while (flag)
{
switch(ans[num++])
{
case 0:
a= ans[ (ans[num]<<4)+ans[num+1] ];
num+=2;
break;
case 1:
ans[ (ans[num]<<4)+ans[num+1] ]=(a&=15);
num+=2;
break;
case 2:
t= a;
a= b;
b= t;
break;
case 3:
a+=b;
b=a>>4;
break;
case 4:
a++;
break;
case 5:
a--;
break;
case 6:
if ( a&15 )
{
num+=2;
break;
}
case 7:
num=(ans[num]<<4)+ans[num+1];
break;
case 8:
flag=0;
break;
default:
break;
}
}
for ( i = 0 ; i < 256 ; i++ )
printf("%c", hax[ans[i]]);
putchar(10);
}
return 0;
}