hdu 5083 Instruction (稍比较复杂的模拟题)
题意:
二进制指令转汇编指令,汇编指令转二进制指令。
思路:
额,条理分好,想全,思维不能乱。
代码:
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 (稍比较复杂的模拟题)的更多相关文章
- [ACM] HDU 5083 Instruction (模拟)
Instruction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- hdu 5641 King's Phone(暴力模拟题)
Problem Description In a military parade, the King sees lots of new things, including an Andriod Pho ...
- HDU 5083 Instruction --模拟
题意:给出汇编指令,解释出编码或者给出编码,解释出汇编指令. 解法:简单模拟,按照给出的规则一步一步来就好了,主要是注意“SET”的情况,还有要输出的东西最好放到最后一起输出,中间如果一旦不对就可以及 ...
- HDU 5083 Instruction(字符串处理)
Problem Description Nowadays, Jim Green has produced a kind of computer called JG. In his computer, ...
- hdu 2629 Identity Card (字符串解析模拟题)
这题是一个字符串模拟水题,给12级学弟学妹们找找自信的,嘿嘿; 题目意思就是要你讲身份证的上的省份和生日解析出来输出就可以了: http://acm.hdu.edu.cn/showproblem.ph ...
- BestCoder15 1002.Instruction(hdu 5083) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5083 题目意思:如果给出 instruction 就需要输出对应的 16-bit binary cod ...
- HDU 5071 Chat(2014鞍山B,模拟)
http://acm.hdu.edu.cn/showproblem.php?pid=5071 Chat Time Limit: 2000/1000 MS (Java/Others) Memory ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力)
HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=59 ...
随机推荐
- 项目需求分析与建议——NABCD模型
特点一:旧物再利用N:需求:在我们的校园生活中,会遇到许多自己用不到的东西例如,学过的课本.废置的闲置物品等,这些"废物"往往占据着许多空间却不能够发挥自身的价值,通过我们的校园二 ...
- jquery动态生成dom(比如append)导致js事件无效
如果无效用这个方法: on() 方法在被选元素及子元素上添加一个或多个事件处理程序. <div id="zkdiv"> <input type="bu ...
- npm WARN ajv-keywords@2.1.1 requires a peer of ajv@^5.0.0 but none is installed. You must install peer dependencies yourself.
解决: npm install -g npm-install-peers npm install -g npm npm i ajv 但是好像没啥用
- Java基础系列(2)- Java开发环境搭建
JDK下载与安装 安装JDK 1.百度搜素JDK8,找到下载地址 2.下载电脑对应的版本 3.双击安装JDK 4.记住安装的路径,可以自定义,默认路径如图 卸载JDK 删除Java安装目录 删除环境变 ...
- 『GoLang』错误处理
Go 没有像 Java 和 .NET 那样的 try/catch 异常机制:不能执行抛异常操作.但是有一套 defer-panic-and-recover 机制. Go 的设计者觉得 try/catc ...
- centos修改ssh默认端口号的方法
修改/etc/ssh/sshd_config配置文件(注意:这里是sshd_config,而不是ssh_config) vi /etc/ssh/sshd_config 在sshd_config文件中添 ...
- 鸿蒙内核源码分析(寄存器篇) | 小强乃宇宙最忙存储器 | 百篇博客分析OpenHarmony源码 | v38.02
百篇博客系列篇.本篇为: v38.xx 鸿蒙内核源码分析(寄存器篇) | 小强乃宇宙最忙存储器 | 51.c.h .o 硬件架构相关篇为: v22.xx 鸿蒙内核源码分析(汇编基础篇) | CPU在哪 ...
- P3235-[HNOI2014]江南乐【整除分块,SG函数】
正题 题目链接:https://www.luogu.com.cn/problem/P3235 题目大意 \(T\)组游戏,固定给出\(F\).每组游戏有\(n\)个石头,每次操作的人可以选择一个数量不 ...
- 使用three.js实现炫酷的酸性风格3D页面
背景 近期学习了 WebGL 和 Three.js 的一些基础知识,于是想结合最近流行的酸性设计风格,装饰一下个人主页,同时总结一些学到的知识.本文内容主要介绍,通过使用 React + three. ...
- Ubuntu系统的开机全流程介绍及grub美化
目录 前言 Ubuntu开机经历的步骤 BIOS Boot Loader Kernel 配置 Grub 的个性化主题 /usr/share/grub/default/grub /etc/default ...