栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 2410 Simple Computers

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375233.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号