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 ...
随机推荐
- 动态规划精讲(一)A单串
单串 单串 dp[i] 线性动态规划最简单的一类问题,输入是一个串,状态一般定义为 dp[i] := 考虑[0..i]上,原问题的解,其中 i 位置的处理,根据不同的问题,主要有两种方式: 第一种是 ...
- Android通过WebView实现新闻界面的加载
原文链接:Android实现WebView加载网页及网页美化(简易新闻 四)_Tobey_r1的博客-CSDN博客 效果展示: 我是按照原文作者的步骤一步步来的,中间没有遇到什么问题.主要是界面中有很 ...
- python+echarts+flask实现对全国疫情数据的爬取并可视化展示
用Python进行数据爬取并存储到数据库,3.15学习总结(Python爬取网站数据并存入数据库) - 天岁 - 博客园 (cnblogs.com) 通过echarts+flask实现数据的可视化展示 ...
- Django学习day10随堂笔记
每日测验 """ 今日考题 1.默写ajax基本语法,及提交json数据和文件都需要添加哪些额外参数 2.什么是序列化,截止目前为止你所接触过的序列化有哪些 3.批量插入 ...
- 彻底搞明白PHP的中引用的概念
之前我们其实已经有过几篇文章讲过引用方面的问题,这次我们来全面的梳理一下引用在PHP到底是怎么回事,它和C中的指针有什么不同,在使用的时候要注意些什么. 什么是引用? 在 PHP 中引用意味着用不同的 ...
- jmeter5.2 性能测试 资源监控 JMeterPlugins1.4 ServerAgent2.2.1
一.性能工具的安装部署 1.下载JMeterPlugins-Standard-1.4.0.zip的安装包 2.解压JMeterPlugins-Standard-1.4.0.zip,将其中\lib\ex ...
- 『Python』优雅的记录日志——loguru
1. 安装 pip install loguru 2. 初识 from loguru import logger logger.debug("This is a debug..." ...
- 深入理解Python切片
Python序列的切片很基础同时也很重要,最近看到一个[::-1]的表达,不明所以,查了一些资料并实际操作,对Python切片有了更深刻的认识,以下结合例子详细说明.先看下切片的基本语法,一般认为切片 ...
- P4323-[JSOI2016]独特的树叶【换根dp,树哈希】
正题 题目链接:https://www.luogu.com.cn/problem/P4323 题目大意 给出\(n\)个点的树和加上一个点之后的树(编号打乱). 求多出来的是哪个点(如果有多少个就输出 ...
- 一凡老师亲录视频,Python从零基础到高级进阶带你飞
如需Q群交流 群:893694563 不定时更新2-3节视频 零基础学生请点击 Python基础入门视频 如果你刚初入测试行业 如果你刚转入到测试行业 如果你想学习Python,学习自动化,搭建自动化 ...