题意:

二进制指令转汇编指令,汇编指令转二进制指令。

思路:

额,条理分好,想全,思维不能乱。

代码:

int findyu(char yu[50],char c){
int l=strlen(yu);
rep(i,0,l-1) if(c==yu[i]) return i;
}
int calc(char t[50],int x,int k){
int res=0;
rep(i,x,x+k-1) res*=10, res+=(t[i]-'0');
return res;
}
int calc2(char t[50]){
int l=strlen(t);
int res=0;
rep(i,0,l-1) res*=2, res+=(t[i]-'0');
return res;
}
void print(int x){
int t1[10];
int c=0;
rep(i,0,4){
t1[++c]=(x&1);
x>>=1;
}
rep2(i,c,1) printf("%d",t1[i]);
}
int main(){
//freopen("test.in","r", stdin); int kind;
map<string,string> mp1;
mp1["ADD"]="000001";
mp1["SUB"]="000010";
mp1["DIV"]="000011";
mp1["MUL"]="000100";
mp1["MOVE"]="000101";
mp1["SET"]="000110";
map<string,string> mp2;
mp2["000001"]="ADD";
mp2["000010"]="SUB";
mp2["000011"]="DIV";
mp2["000100"]="MUL";
mp2["000101"]="MOVE";
mp2["000110"]="SET";
while(scanf("%d",&kind)!=EOF){
if(kind==1){
char ins[50],yu[50];
int ra,rb=0;
scanf("%s%s",ins,yu);
if(strcmp(ins,"SET")==0)
ra=calc(yu,1,strlen(yu)-1);
else{
int tc=findyu(yu,',');
ra=calc(yu,1,tc-1);
rb=calc(yu,tc+2,strlen(yu)-tc-2);
}
cout<<mp1[string(ins)];
if(ins=="SET"){
print(ra);
printf("00000\n");
continue;
}
print(ra);
print(rb);
cout<<endl;
continue;
}
else{
char str[50];
scanf("%s",str);
if(strlen(str)!=16){
cout<<"Error!"<<endl;
continue;
}
char ope[50],rra[50],rrb[50];
rep(i,0,5) ope[i]=str[i]; ope[6]=0;
rep(i,6,10) rra[i-6]=str[i]; rra[5]=0;
rep(i,11,15) rrb[i-11]=str[i]; rrb[5]=0;
int ra=calc2(rra);
int rb=calc2(rrb);
if(strcmp(ope,"000110")==0){
if(rb!=0){
cout<<"Error!"<<endl;
continue;
}
if(ra<1 || ra>31){
cout<<"Error!"<<endl;
continue;
}
printf("SET R%d\n",ra);
continue;
}
if(ra<1 || ra>31 || rb<1 || rb>31){
cout<<"Error!"<<endl;
continue;
}
if(mp2[string(ope)]==""){
cout<<"Error!"<<endl;
continue;
}
cout<<mp2[string(ope)];
printf(" R%d,R%d\n",ra,rb);
continue;
}
} //fclose(stdin);
}

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 5641 King's Phone(暴力模拟题)

    Problem Description In a military parade, the King sees lots of new things, including an Andriod Pho ...

  3. HDU 5083 Instruction --模拟

    题意:给出汇编指令,解释出编码或者给出编码,解释出汇编指令. 解法:简单模拟,按照给出的规则一步一步来就好了,主要是注意“SET”的情况,还有要输出的东西最好放到最后一起输出,中间如果一旦不对就可以及 ...

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

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

  5. hdu 2629 Identity Card (字符串解析模拟题)

    这题是一个字符串模拟水题,给12级学弟学妹们找找自信的,嘿嘿; 题目意思就是要你讲身份证的上的省份和生日解析出来输出就可以了: http://acm.hdu.edu.cn/showproblem.ph ...

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

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

  7. HDU 5071 Chat(2014鞍山B,模拟)

    http://acm.hdu.edu.cn/showproblem.php?pid=5071 Chat Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  8. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  9. HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力)

    HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=59 ...

随机推荐

  1. CodeForce-799B T-shirt buying (STL_set)

    有 n 件T恤.第 i 件T恤的价格为 pi .每个T恤有两面,第 i 件T恤正面颜色为 ai ,反面颜色为 bi . 有 m 个人想买T恤,每个人都恰好买一件.第 j 个人最喜欢颜色 cj. 一个人 ...

  2. CentOS8部署nextcloud网盘

    Nextcloud是一款开源的存储软件,功能丰富,支持多人协同工作,目前完全免费. 官网:https://www.nextcloud.com 架构:LAMP或LNMP 本文以LAMP为基础 注意:ph ...

  3. Python程序调用摄像头实现人脸识别

    使用简单代码实现摄像头进行在线人脸识别 import cv2 import sys import logging as log import datetime as dt from time impo ...

  4. Django边学边记——中间件

    特点 Django中的中间件是一个轻量级.底层的插件系统,可以介入Django的请求和响应处理过程,用于全局修改Django的输入或输出. 每个中间件组件负责做一些特定的功能.中间件全部注册在sett ...

  5. web、app、小程序测试异同点

    http://www.spasvo.com/Company/news_show.asp?id=702 https://blog.csdn.net/weixin_43489515/article/det ...

  6. PolarDB PostgreSQL Buffer Management 原理

    背景介绍 传统数据库的主备架构,主备有各自的存储,备节点回放WAL日志并读写自己的存储,主备节点在存储层没有耦合.PolarDB的实现是基于共享存储的一写多读架构,主备使用共享存储中的一份数据.读写节 ...

  7. P5319-[BJOI2019]奥术神杖【0/1分数规划,AC自动机,dp】

    正题 题目链接:https://www.luogu.com.cn/problem/P5319 题目大意 一个长度为\(n\)的串\(T\),用\(0\sim 9\)填充所有的\(.\). 然后给出\( ...

  8. mysql8.0.20安装配置教程

    mysql配置安装教程 1.下载mysql8.0.20安装包 下载地址: https://dev.mysql.com/downloads/mysql/.找到安装包后下载.(官网为英文,如果看不懂的小伙 ...

  9. 洛谷2093 JZPFAR + KD-Tree学习笔记 (KD-Tree)

    KD-Tree这玩意还真的是有趣啊.... (基本完全不理解) 只能谈一点自己的对KD-Tree的了解了. 首先这个玩意就是个暴力... 他的结构有点类似二叉搜索树 每一层都是以一个维度作为划分标准. ...

  10. CF487E Tourists + 圆方树学习笔记(圆方树+树剖+线段树+multiset)

    QWQ果然我已经什么都学不会的人了. 这个题目要求的是图上所有路径的点权和!QWQ(我只会树上啊!) 这个如果是好啊 这时候就需要 圆方树! 首先在介绍圆方树之前,我们先来一点简单的前置知识 首先,我 ...