HDU 5083 Instruction --模拟
题意:给出汇编指令,解释出编码或者给出编码,解释出汇编指令。
解法:简单模拟,按照给出的规则一步一步来就好了,主要是注意“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 --模拟的更多相关文章
- [ACM] HDU 5083 Instruction (模拟)
Instruction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- hdu 5083 Instruction (稍比较复杂的模拟题)
题意: 二进制指令转汇编指令,汇编指令转二进制指令. 思路: 额,条理分好,想全,思维不能乱. 代码: int findyu(char yu[50],char c){ int l=strlen(yu) ...
- HDU 5083 Instruction(字符串处理)
Problem Description Nowadays, Jim Green has produced a kind of computer called JG. In his computer, ...
- BestCoder15 1002.Instruction(hdu 5083) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5083 题目意思:如果给出 instruction 就需要输出对应的 16-bit binary cod ...
- hdu 5083 有坑+字符串模拟水题
http://acm.hdu.edu.cn/showproblem.php?pid=5083 机器码和操作互相转化 注意SET还要判断末5位不为0输出Error #pragma comment(lin ...
- hdu 5083(模拟)
Instruction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Instruction (hdu 5083)
Instruction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 4121 Xiangqi 模拟题
Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...
- hdu 5071 Chat(模拟)
题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...
随机推荐
- Html 网页布局(一)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...
- Verilog学习笔记设计和验证篇(一)...............总线和流水线
总线 总线是运算部件之间数据流通的公共通道.在硬线逻辑构成的运算电路中只要电路的规模允许可以比较自由的确定总线的位宽,从而大大的提高数据流通的速度.各个运算部件和数据寄存器组可以通过带有控制端的三态门 ...
- redis3.0 集群实战2 - 集群功能实战
1 集群基本操作 1.1 查看当前集群状态 使用redis-trib.rb check功能查看对应的节点的状态: [root@bogon bin]# ./redis-trib.rb check 1 ...
- expect入门--自动化linux交互式命令
很多linux程序比如passwd,ftp,scp,ssh等自身并没有提供一种静默式的执行选项,而是依赖于运行时的终端输入来进行后一步的操作比如更改密码.文件上传.下载等.虽然有些编程语言如java嵌 ...
- IE11出现“__doPostBack未定义”的解决办法。
方法一:浏览器设置成兼容模式,这个是超级掩耳盗铃方法,你就没想过其他人也会出这个问题. 方法二.安装服务器版的.Net40的补丁.http://download.csdn.net/detail/565 ...
- 配置文件,环境配置和war报分离,方便生产更改
在生产环境实现配置文件和war包 的分离,为方便在必要的时候进行一定的更改,可以避免修改包,但是需要重启 最初为这样的选择配置,单不知为何未生效,修改为配置2配置方法,但不灵活,待跟进.配置1: &l ...
- CSS动态伪类选择器温故-3
动态伪类选择器 伪类选择器:大家熟悉的:[:link][:visited][:hover][:active]CSS3的伪类选择器分为六种:(1)动态伪类选择器(2)目标伪类选择器(3)语言伪类选择器( ...
- Sass学习之路(3)——Sass编译
Sass的编译也是在我们使用Sass的时候必须要经过的一个步骤,因为".sass"和".scss"文件并不能直接使用<link>标签引用,最终其实还 ...
- Access sql语句创建表及字段类型
创建一张空表: Sql="Create TABLE [表名]" 创建一张有字段的表: Sql="Create TABLE [表名]([字段名1] MEMO NOT NUL ...
- 解决SharePoint 2013 designer workflow 在发布的报错“负载平衡没有设置”The workflow files were saved but cannot be run.
原因是app management service没有设置好,在管理中心把他删掉,重新建一个就可以了 Provision App Management Service In SharePoint 20 ...