poj 1049 Microprocessor Simulation

简单的模拟,读懂了题就会做了
#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;
}

posted on 2011-08-12 09:53 purplest 阅读(248) 评论(0)  编辑 收藏 引用 所属分类: 模拟


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理


<2011年9月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

导航

统计

常用链接

留言簿

随笔分类(70)

随笔档案(68)

ACMer

搜索

最新随笔

最新评论