poj 2410 Simple Computers

poj 2410 Simple Computers,第1张

poj 2410 Simple Computers
#include <iostream>using namespace std;const    int maxn=32;int        byte[maxn];void init(){    int        i;    for (i=1;i<=31;i++)        cin>>byte[i];}int num(int add){    int        x=0,temp=1;    while (add)    {        x+=add%10*temp;        add/=10;        temp*=2;    }    return x;}int    binary(int h){    int        bin[9],x=0,i,ans=0;    while (h)    {        bin[++x]=h%2;        h/=2;    }    for (i=x;i>=1;i--)        ans=ans*10+bin[i];    return ans;}void inc(int &accu){    int        i=1,temp;    temp=num(accu)+1;    if (temp>255)        temp=0;    accu=binary(temp);}void dec(int &accu){    int        i=1,temp;    temp=num(accu)-1;    if (temp<0)        temp=255;    accu=binary(temp);}int work(){    int        accu=0,pc=0,x,ord;    while (true)    {        x=num(byte[pc]%100000);        ord=byte[pc]/100000;        pc++;        if (pc>31) pc=0;        switch(ord)        { case 0    :     byte[x]=accu;     break; case 1    :     accu=byte[x];     break; case 10    :     pc=accu==0?x:pc;     break; case 11    :     break; case 100:     dec(accu);     break; case 101:     inc(accu);     break; case 110:     pc=x;     break; case 111:     return accu;     break;        }    }}void make(int x){    int        temp=10000000;    if (x==0)    {        cout<<"00000000n";        return;    }    while (x/temp==0)    {        cout<<"0";        temp/=10;    }    cout<<x<<endl;}int main(){    while (cin>>byte[0])    {        init();        make(work());    }    return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4918792.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存