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 ...
随机推荐
- xshell下载文件到本地/上传文件到服务器
xshell很好用,然后有时候想在windows和linux上传或下载某个文件,其实有个很简单的方法就是rz,sz首先你的Ubuntu需要安装rz.sz(如果没有安装请执行以下命令,安装完的请跳过.其 ...
- Java生成公私钥对
public static synchronized KeyPair generateRSAKeyPair(int keysize, BigInteger publicExponent) { try ...
- zeromq 学习和python实战
参考文档: 官网 http://zeromq.org/ http://www.cnblogs.com/rainbowzc/p/3357594.html 原理解读 zeromq只是一层针对socke ...
- Mysql基本数据操作
一.mysql中的逻辑对象 mysqld(process_id(threads)+memory+datadir)-->库-->表-->记录(由行与列组成) 什么是关系型数据库:表与表 ...
- SharePoint 2013 单一页面赋设计权限
本文介绍SharePoint的使用中,断开单一页面权限,给用户编辑权限以及操作中遇到的问题,希望给相关需要的人一个参考. 1.首先进入页面库,找到我们的页面,进入共享,如下图: 2.在弹出的窗口中选择 ...
- Android-Application
1:Application是什么? Application和Activity,Service一样,是android框架的一个系统组件,当android程序启动时系统会创建一个 application对 ...
- Effective Java 阅读笔记——枚举和注解
30:用enum代替int常量 当需要一组固定常量的时候,应该使用enum代替int常量,除了对于手机登资源有限的设备应该酌情考虑enum的性能弱势之外. 31:用实例域代替序数 应该给enum添加i ...
- HTTPAnalyzer截获SoapUI发送的接口报文
一.截获过程 1. 开启HTTPAnalyzer报文截获工具. 2. 通过SoapUI工具发送报文. 3. HTTPAnalyzer报文截获工具自动截获. 二.SoapUI报文准备 准备工作是:打 ...
- ASCII
0. American Standard Code of Information Interchange 美国信息交换标准码, 即ASCII, 定义表如下: Bin(二进制) Oct(八进制) Dec ...
- 编译时:virtual memory exhausted: Cannot allocate memory
一.问题 当安装虚拟机时系统时没有设置swap大小或设置内存太小,编译程序会出现virtual memory exhausted: Cannot allocate memory的问题,可以用swap扩 ...