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 ...
随机推荐
- Android5.0新特性——兼容性(support)
兼容性 虽然Material Design新增了许多新特性,但是并不是所有新内容对对下保持了兼容. 使用v7包 v7 support libraries r21 及更高版本包含了以下Material ...
- Android Studio 中 FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':compileDebugAidl'.的问题解答
Android Studio 中 FAILURE: Build failed with an exception. * What went wrong: Execution failed for ta ...
- django性能优化
1. 内存.内存,还是加内存 2. 使用单独的静态文件服务器 3. 关闭KeepAlive(如果服务器不提供静态文件服务,如:大文件下载) 4. 使用memcached 5. 使用select_rel ...
- .NET破解之分享给新注册的朋友
前些日子,在论坛里看了有人发过这个软件,也有大神分析过网络版,如果是重帖,请删除吧:正好11.11注册了很多新会员,给他们一个见面礼吧,抛砖引玉,我才来论坛的时候,也是看着前人教程慢慢学习的:好久没冒 ...
- JS常用的三种匿名函数
第一种: var f1=function(p1,p2){ return p1+p2; };//将函数赋值给一个变量 alert(f1(1,3)); 匿名函数没法调用,只能赋值给一个变量,由于是赋值语句 ...
- (转)解决ScrollView嵌套ListView或者GridView导致只显示一行的方法
即动态获取ListView和GridView的高度 一.对于ListView ListView listview= new ListView(this); setListViewHeightBased ...
- Gnome排序算法
Gnome排序(地精排序),起初由Hamid Sarbazi-Azad 于2000年提出,并被称为stupid排序,后来被Dick Grune描述并命名为“地精排序”,作为一个排序算法,和插入排序类似 ...
- Android 6.0权限管理
Android 6.0权限管理 关于权限管理 Android6.0 发布之后,Android 的权限系统被重新设计.在 23 之前 App 的权限只会在用户安装的时候询问一次,App一旦安装后就可以使 ...
- Spring(四)Bean注入方试
一.构造方法注入 定义:通过构造函数来完成依赖关系的设定 优缺点: 在构造对象的同时,完成依赖关系的建立 如果关联的对象很多,那和不得不在构造方法上加入过多的参数 基中有index:如果指定索引从0开 ...
- C语言错误之--初始值(低级错误)
今天犯了一个低级错误,虽然低级,但是也不能忽视,一个低级错误以后可能小则浪费时间和精力,大则酿成整个app的项目bug.