题意:给出汇编指令,解释出编码或者给出编码,解释出汇编指令。

解法:简单模拟,按照给出的规则一步一步来就好了,主要是注意“SET”的情况,还有要输出的东西最好放到最后一起输出,中间如果一旦不对就可以及时跳出去。

其他也没什么了,只要细心点,多测几组样例就好了。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
#define N 100007 string op[] = {"ADD","SUB","DIV","MUL","MOVE","SET"};
string bop[] = {"","","","","",""};
string bina[],itostr[]; void init()
{
for(int i=;i<;i++)
{
string now = "";
int tmp = i;
for(int j=;j<;j++)
{
if(tmp%) now += "";
else now += "";
tmp /= ;
}
reverse(now.begin(),now.end());
bina[i] = now; //i的二进制形式 tmp = i;
string no = "";
while(tmp)
{
no += tmp%+'';
tmp/=;
}
reverse(no.begin(),no.end());
itostr[i] = no; //i的十进制形式
}
} int main()
{
string num,A;
char ss[],R1,R2;
int sign,i,j,a,b;
init();
while(scanf("%d",&sign)!=EOF)
{
if(sign == )
{
cin>>A;
getchar();
if(A != "SET")
scanf("%c%d,%c%d",&R1,&a,&R2,&b);
else
scanf("%c%d",&R1,&a);
for(i=;i<;i++)
{
if(A == op[i])
break;
}
if(i == ) { puts("Error!"); continue; }
if(A != "SET")
{
if(R1 != 'R' || R2 != 'R' || a <= || a >= || b <= || b >=)
{
puts("Error!");
continue;
}
cout<<bop[i]<<bina[a]<<bina[b]<<endl;
}
else
{
if(R1 != 'R'|| a <= || a >= )
{
puts("Error!");
continue;
}
cout<<bop[i]<<bina[a]<<""<<endl;
}
}
else
{
cin>>num;
string A,B,C;
string oA,oB,oC;
A = num.substr(,);
B = num.substr(,);
C = num.substr(,);
for(i=;i<;i++)
{
if(A == bop[i])
break;
}
if(i == ) { puts("Error!"); continue; }
oA = op[i];
if(op[i] != "SET")
{
for(i=;i<;i++)
{
if(B == bina[i])
break;
}
if(i == ) { puts("Error!"); continue; }
oB = "R"+itostr[i];
for(i=;i<;i++)
{
if(C == bina[i])
break;
}
if(i == ) { puts("Error!"); continue; }
oC = "R"+itostr[i];
cout<<oA<<" "<<oB<<","<<oC<<endl;
}
else
{
if(C != "") { puts("Error!"); continue;}
for(i=;i<;i++)
{
if(B == bina[i])
break;
}
if(i == ) { puts("Error!"); continue; }
oB = "R"+itostr[i];
cout<<oA<<" "<<oB<<endl;
}
}
}
return ;
}

HDU 5083 Instruction --模拟的更多相关文章

  1. [ACM] HDU 5083 Instruction (模拟)

    Instruction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  2. hdu 5083 Instruction (稍比较复杂的模拟题)

    题意: 二进制指令转汇编指令,汇编指令转二进制指令. 思路: 额,条理分好,想全,思维不能乱. 代码: int findyu(char yu[50],char c){ int l=strlen(yu) ...

  3. HDU 5083 Instruction(字符串处理)

    Problem Description Nowadays, Jim Green has produced a kind of computer called JG. In his computer, ...

  4. BestCoder15 1002.Instruction(hdu 5083) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5083 题目意思:如果给出 instruction 就需要输出对应的 16-bit binary cod ...

  5. hdu 5083 有坑+字符串模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5083 机器码和操作互相转化 注意SET还要判断末5位不为0输出Error #pragma comment(lin ...

  6. hdu 5083(模拟)

    Instruction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. Instruction (hdu 5083)

    Instruction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  8. HDU 4121 Xiangqi 模拟题

    Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...

  9. hdu 5071 Chat(模拟)

    题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...

随机推荐

  1. 亲们! 首次见面! 带来不适!多多见谅!--------->>Bank系统

    亲们!您们好! 讲一下Bank系统的做法: 01.首先创建一个Card类 using System; using System.Collections.Generic; using System.Li ...

  2. 【iOS】Quartz2D基本图形

    一.画线段 - (void)drawRect:(CGRect)rect { // Drawing code // 1.获得图形上下文 CGContextRef ctx = UIGraphicsGetC ...

  3. mysql命令行备份数据库

    MySQL数据库使用命令行备份|MySQL数据库备份命令 例如: 数据库地址:127.0.0.1 数据库用户名:root 数据库密码:pass 数据库名称:myweb 备份数据库到D盘跟目录 mysq ...

  4. [zz] JIT&HotSpot

    zz from 百度百科 最早的Java建置方案是由一套转译程式(interpreter),将每个Java指令都转译成对等的微处理器指令,并根据转译后的指令先后次序依序执行,由于一个Java指令可能被 ...

  5. JavaScript hasOwnProperty() 函数详解

    hasOwnProperty()函数用于指示一个对象自身(不包括原型链)是否具有指定名称的属性.如果有,返回true,否则返回false. 该方法属于Object对象,由于所有的对象都"继承 ...

  6. SAP_Web_Service开发配置

    第一章    SAP创建WS 1.1       概要技术说明 1.2       创建RFC函数 1.3       创建WS 1.4       外部系统访问配置 第二章    SAP调用WS 2 ...

  7. Unity3D事件函数的执行顺序 - 包含渲染等模块的完整版,中英文对照

    原文地址: http://www.cnblogs.com/ysdyaoguai/p/3746828.html In Unity scripting, there are a number of eve ...

  8. Cocos2d-X-3.0之后的版本的环境搭建

    由于cocos2d游戏开发引擎更新十分频繁,官方文档同步不够及时和完善.所以不要照着官方文档来照做生成工程. <点击图片就能进入网站> 具体的步骤: 1.获取cocos2d-X的源码v3. ...

  9. Mac平台下启动MySQL到完全终止MySQL----终端八步走

    1.选中Finder的情况下,快捷键进入搜索目录:/usr/local 然后进入mysql目录下: 2.右键 "从这里启动" 打开终端: 3.输入执行:./scripts/mysq ...

  10. Swift中的类和结构体的相同点与不同点

     相同点: 1.都是有内部变量和函数 2.都可以有内部下标方式去取属性 3.都可以有初始化函数 4.都可以用协议   不同点: 1.类有继承 2.类可以多重引用 3.类有析构