題意:兩種串讓你互相轉換,前六位對應一個字符串,中間五位和後五位分別對應一個二進制數值
題解:沒什麼難度,只是有一點不符合的就算非法,有兩個要考慮的細節,首先SET的時候後面R2是爲0的 其次注意b、c的範圍
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#define mem(x,y) memset(x,y,sizeof(x))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,double> pii;
#define bug puts("===========");
#define zjc puts("");
const double pi=(acos(-1.0));
const double eps=1e-8;
const ll INF=1e18+10;
const ll inf=1e9+10;
const int mod=1e9+7;
const int maxn=100000+10;
const int maxm=1e6+5;
map<string,string> MP;
map<string,string>mp;
char aa[1005];
int la;
bool in(int x){
return x>=1&&x<=31;
}
void OT(int a){
char ans[10];
ans[5]='\0';
for(int i=4; i>=0; i--){
ans[i]=a%2+'0';
a/=2;
}
printf("%s",ans);
}
void go(int n){
string a;
int i,b=0,c=0;
for(i=0; aa[i]!=' '&&i<la; i++) a+=aa[i];
if(n!=1||aa[i]!=' '||aa[i+1]!='R'||MP.count(a)==0){
puts("Error!");
return;
}
for(i=i+2; i<la&&aa[i]<='9'&&aa[i]>='0'; i++) b=b*10+aa[i]-'0';
if(a=="SET"){
if(!in(b)||i!=la){
puts("Error!");
return;
}
printf("000110"); OT(b);OT(0);puts("");
return;
}
if(aa[i]!=','||aa[i+1]!='R'){
puts("Error!");
return;
}
for(i=i+2; i<la&&aa[i]<='9'&&aa[i]>='0'; i++) c=c*10+aa[i]-'0';
if(!in(b)||!in(c)||i!=la){
puts("Error!");
return;
}
cout<<MP[a]; OT(b);OT(c); puts("");
return;
}
void initmp(){
mp["000001"]="ADD";
mp["000010"]="SUB";
mp["000011"]="DIV";
mp["000100"]="MUL";
mp["000101"]="MOVE";
mp["000110"]="SET";
MP["ADD"]= "000001";
MP["SUB"]= "000010";
MP["DIV"]= "000011";
MP["MUL"]= "000100";
MP["MOVE"]="000101";
MP["SET"]= "000110";
}
void go2(){
string a;
for(int i=0; i<6; i++) a+=aa[i];
if(la!=16||mp.count(a)==0){
puts("Error!");
return;
}
int b=0,c=0;
for(int i=6;i<11;i++) b=b*2+aa[i]-'0';
for(int i=11;i<16;i++) c=c*2+aa[i]-'0';
if(!in(b)){
puts("Error!");
return;
}
if(a=="000110"){
if(c!=0) puts("Error!");
else cout<<mp[a]<<" R"<<b<<endl;
return;
}
if(!in(c)){
puts("Error!");
return;
}
cout<<mp[a]<<" R"<<b<<",R"<<c<<endl;
}
int main()
{
initmp();
int n;
while(~scanf("%d",&n)){
getchar();
gets(aa);
la=strlen(aa);
if(n) go(n);
else go2();
}
return 0;
}