Instruction (hdu 5083)
Instruction
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 343 Accepted Submission(s): 99
and R2, then store the result to R1. But this instruction cannot be execute directly by computer, before this instruction is executed, it must be changed to binary code which can be executed by computer. Each instruction corresponds to a 16-bit binary code.
The higher 6 bits indicates the operation code, the middle 5 bits indicates the destination operator, and the lower 5 bits indicates the source operator. You can see Form 1 for more details.
code(6 bits)109destination
operator code(5 bits)54source
operator code(5 bits)0Form
1
In JG system there are 6 instructions which are listed in Form 2.
Ra,RbSUB Ra,RbDIV
Ra,RbMUL Ra,RbMOVE
Ra,RbSET RafunctionAdd
the number in register Ra and Rb, then store the result to Ra.Subtract
the number in register Ra to Rb, then store the result to Ra.Divide
the number in register Ra by Rb, then store the result to Ra.Mulplicate
the number in register Ra and Rb, then store the result to Ra.Move
the number in register Rb to Ra.Set 0 to Ra.Form
2
Operation code is generated according to Form 3.
code000001000010000011000100000101000110Form
3
Destination operator code and source operator code is the register code of the register which is related to.
There are 31 registers in total. Their names are R1,R2,R3…,R30,R31. The register code of Ri is the last 5 bits of the number of i in the binary system. For eaxample the register code of R1 is 00001, the register code of R2 is 00010, the register code of R7
is 00111, the register code of R10 is 01010, the register code of R31 is 11111.
So we can transfer an instruction into a 16-bit binary code easyly. For example, if we want to transfer the instruction ADD R1,R2, we know the operation is ADD whose operation code is 000001, destination operator code is 00001 which is the register code of
R1, and source operator code is 00010 which is the register code of R2. So we joint them to get the 16-bit binary code which is 0000010000100010.
However for the instruction SET Ra, there is no source register, so we fill the lower 5 bits with five 0s. For example, the 16-bit binary code of SET R10 is 0001100101000000
You are expected to write a program to transfer an instruction into a 16-bit binary code or vice-versa.
First line contains a type sign, ‘0’ or ‘1’.
‘1’ means you should transfer an instruction into a 16-bit binary code;
‘0’ means you should transfer a 16-bit binary code into an instruction.
For the second line.
If the type sign is ‘1’, an instruction will appear in the standard form which will be given in technical specification;
Otherwise, a 16-bit binary code will appear instead.
Please process to the end of file.
[Technical Specification]
The standard form of instructions is
ADD Ra,Rb
SUB Ra,Rb
DIV Ra,Rb
MUL Ra,Rb
MOVE Ra,Rb
SET Ra
which are also listed in the Form 2.
1≤a,b≤31
There is exactly one space after operation, and exactly one comma between Ra and Rb other than the instruction SET Ra. No other character will appear in the instruction.
line.
For type ‘1’, transfer the instruction into 16-bit binary code and output it in a single line.
1
ADD R1,R2
0
0000010000100010
0
1111111111111111
0000010000100010
ADD R1,R2
Error!
pid=5085" target="_blank" style="color:rgb(26,92,200); text-decoration:none">5085
5084 5081pid=5080" target="_blank" style="color:rgb(26,92,200); text-decoration:none">5080
5079。代码比較乱啊啊啊啊啊
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#pragma comment (linker,"/STACK:102400000,102400000")
#define maxn 1005
#define MAXN 2005
#define mod 1000000009
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-6
typedef long long ll;
using namespace std; char ope[6][5]={{"ADD"},{"SUB"},{"DIV"},{"MUL"},{"MOVE"},{"SET"}};
char code[6][7]={{"000001"},{"000010"},{"000011"},{"000100"},{"000101"},{"000110"}};
char co[31][6]={ {"00001"} , {"00010"} , {"00011"} , {"00100"} , {"00101"} , {"00110"} , {"00111"} , {"01000"} , {"01001"} , {"01010"}
, {"01011"} , {"01100"} , {"01101"} , {"01110"} , {"01111"} , {"10000"} , {"10001"} , {"10010"} , {"10011"} , {"10100"}
, {"10101"} , {"10110"} , {"10111"} , {"11000"} , {"11001"} , {"11010"} , {"11011"} , {"11100"} , {"11101"} , {"11110"}
, {"11111"}};
char s1[5],s2[10]; int OP(char str[])
{
for (int i=0;i<6;i++)
{
if (strcmp(str,ope[i])==0)
return i;
}
} int main()
{
int n;
while (~scanf("%d",&n))
{
if (n==1)
{
scanf("%s%s",s1,s2);
int x=OP(s1);
int dd=x;
printf("%s",code[x]);
x=s2[1]-'0';
int ok=0;
if (isdigit(s2[2]))
{
ok=1;
x=x*10;
x=x+s2[2]-'0';
}
x--;
printf("%s",co[x]);
if (dd==5)
{
printf("00000\n");
continue;
}
if (ok)
{
x=s2[5]-'0';
if (isdigit(s2[6]))
{
x=x*10;
x=x+s2[6]-'0';
}
}
else
{
x=s2[4]-'0';
if (isdigit(s2[5]))
{
x=x*10;
x=x+s2[5]-'0';
}
}
x--;
printf("%s\n",co[x]);
}
else if (n==0)
{
scanf("%s",s1);
int len=strlen(s1);
int t=1;
int sum=0;
for (int i=5;i>=0;i--)
{
int x=s1[i]-'0';
sum+=t*x;
t=t*2;
}
if (sum>6||sum==0)
{
printf("Error!\n");
continue;
}
sum--;
int o=sum;
int flag=sum;
// printf("%s",ope[sum]);
t=1;
sum=0;
for (int i=10;i>=6;i--)
{
int x=s1[i]-'0';
sum+=t*x;
t=t*2;
}
if (sum>31||sum==0)
{
printf("Error!\n");
continue;
}
int aa=sum;
// printf(" R%d",sum);
if (flag==5)
{
t=1;
sum=0;
for (int i=15;i>=11;i--)
{
int x=s1[i]-'0';
// printf("x=%d\n",x);
sum+=t*x;
t=t*2;
}
if (sum==0)
{
printf("%s",ope[o]);
printf(" R%d",aa);
printf("\n");
continue;
}
else
{
printf("Error!\n");
continue;
}
}
t=1;
sum=0;
for (int i=15;i>=11;i--)
{
int x=s1[i]-'0';
// printf("x=%d\n",x);
sum+=t*x;
t=t*2;
}
if (sum>31||sum==0)
{
printf("Error!\n");
continue;
}
printf("%s",ope[o]);
printf(" R%d",aa);
printf(",R%d\n",sum);
}
}
return 0;
}
Instruction (hdu 5083)的更多相关文章
- 2道acm编程题(2014):1.编写一个浏览器输入输出(hdu acm1088);2.encoding(hdu1020)
//1088(参考博客:http://blog.csdn.net/libin56842/article/details/8950688)//1.编写一个浏览器输入输出(hdu acm1088)://思 ...
- Bestcoder13 1003.Find Sequence(hdu 5064) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5064 题目意思:给出n个数:a1, a2, ..., an,然后需要从中找出一个最长的序列 b1, b ...
- 2013 多校联合 F Magic Ball Game (hdu 4605)
http://acm.hdu.edu.cn/showproblem.php?pid=4605 Magic Ball Game Time Limit: 10000/5000 MS (Java/Other ...
- (多线程dp)Matrix (hdu 2686)
http://acm.hdu.edu.cn/showproblem.php?pid=2686 Problem Description Yifenfei very like play a num ...
- War Chess (hdu 3345)
http://acm.hdu.edu.cn/showproblem.php?pid=3345 Problem Description War chess is hh's favorite game:I ...
- 2012年长春网络赛(hdu命题)
为迎接9月14号hdu命题的长春网络赛 ACM弱校的弱菜,苦逼的在机房(感谢有你)呻吟几声: 1.对于本次网络赛,本校一共6名正式队员,训练靠的是完全的自主学习意识 2.对于网络赛的群殴模式,想竞争现 ...
- BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)
Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- BestCoder Round #68 (div.2) geometry(hdu 5605)
geometry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- 2013多校联合2 I Warm up 2(hdu 4619)
Warm up 2 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total ...
随机推荐
- build tree
有二叉树的前序遍历和后序遍历,构造二叉树 /** * Definition for binary tree * public class TreeNode { * int val; * TreeNod ...
- 练习2 E题 - 求奇数的乘积
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description 给你n ...
- 初级ant的学习
一.安装ant 到官方主页http://ant.apache.org下载新版(目前为Ant1.8.1)的ant,得到的是一个apache-ant-1.8.1-bin.zip的压缩包.将其解压到你的硬盘 ...
- 40个Android问题
1. Android的四大组件是哪些,它们的作用? 答:Activity:Activity是Android程序与用户交互的窗口,是Android构造块中最基本的一种,它需要为保持各界面的状态,做很多持 ...
- noip2014 考试总结
noip:最初估分580,明间数据:570,初测估分:510-570,最终得分:570 这次noip怎么说呢,发挥的还是比较理想吧,不过还是犯了一些“低级错误”,虽然没有造成十分严重的后果,但是还是不 ...
- MIST
获取当前状态机 modelObj.states[modelObj.curStatus.stateId] "FH_Search" modelObj.states[modelObj.p ...
- 如何监控 Nginx?
什么是 Nginx? Nginx("engine-x")是一个 HTTP 和反向代理服务器,同时也是一个邮件代理服务器和通用的 TCP 代理服务器.作为一个免费开源的服务器,Ngi ...
- Java Servlet的request使用的编码引发的思考 以及解决方法
如果我们用浏览器填写了中文,而在服务器Servlet上没有进行编码设置,那么将会出现乱码. 出现乱码的原因是:浏览器发送的文字是以UTF-8编码发送的,然后调用request.getParameter ...
- 【 UVALive - 4287】Proving Equivalences (SCC缩点)
题意: 给出N个命题,要求你证明这N个命题的等价性 比如有4个命题a,b,c,d,我们证明a<->b, b<->c,c<->d,每次证明都是双向的,因此一共用了6次 ...
- 关于spring3中No Session found for current thread!and Transaction的配置和管理(转)
今天我是特别的郁闷,本来项目做到一半,以前都好好的,结果下午就出现问题,苦逼的到现在才解决.它出现问题的时候都一声不坑, ,(天啦,现在才发现CSDN啥时候把QQ表情给整过来了)就在注册用户的时候,咦 ...