题意:

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

思路:

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

代码:

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. 【简单数据结构】并查集--洛谷 P1111

    题目背景 AA地区在地震过后,连接所有村庄的公路都造成了损坏而无法通车.政府派人修复这些公路. 题目描述 给出A地区的村庄数NN,和公路数MM,公路是双向的.并告诉你每条公路的连着哪两个村庄,并告诉你 ...

  2. STM32CbueIDE 体验

    STM32CbueIDE 体验 下载安装 官网下载链接:https://www.st.com/zh/development-tools/stm32cubeide.html. 软件启动时会令设置工作目录 ...

  3. mysql中varchar类型和datetime类型字段进行比较

    我是在mysql5.7版本进行比较 表a的字段order_no和表iwebshop_tmp的字段order_no一样 需要更新iwebshop_member_order表的datetime类型expi ...

  4. Java基础系列(32)- 递归讲解

    递归 A方法调用B方法,我们很容易理解 递归就是:A方法调用A方法!就是自己调用自己 利用递归可以用简单的程序来解决一些复杂的问题.它通常把一个大型复杂的问题层层转化为一个与原问题相似的规模较小的问题 ...

  5. Leetcode 矩阵置零

    题目描述(中等难度) 给定一个 m x n 的矩阵,如果一个元素为 0 ,则将其所在行和列的所有元素都设为 0 .请使用 原地 算法. 进阶: 一个直观的解决方案是使用  O(mn) 的额外空间,但这 ...

  6. 大前端快闪二:react开发模式 一键启动多个服务

    最近全权负责了一个前后端分离的web项目,前端使用create-react-app, 后端使用golang做的api服务. npx create-react-app my-app cd my-app ...

  7. instanceof和类型转换

    什么是instanceof 判断一个对象是什么类型 注意点 X 和 Y 必须要有父子关系 否则编译都会失败 X对象只要是Y的子类(无论 是 儿子 还是 孙子 还是 曾孙....)X instanceo ...

  8. 感恩笔记之二_SQL语句扩展功能

    前言导读: 本章是对SQL语句基础功能中,一些功能用法的扩展使用的总结,都是实际工作中一些经验的积累. 1 select列查询功能组合使用 --1 函数处理+列计算+列改名 select 函数(列) ...

  9. 极简SpringBoot指南-Chapter01-如何用Spring框架声明Bean

    仓库地址 w4ngzhen/springboot-simple-guide: This is a project that guides SpringBoot users to get started ...

  10. 题解 [BJOI2019]奥术神杖

    题目传送门 题目大意 给出一个残缺的字符串,每个位置都 \(\in[0,9]\).有 \(m\) 中贡献,即 \(s,k\),表示该字符串中没出现一次 \(s\),贡献便乘上 \(k\).最后对贡献求 ...