HDU 5083 Instruction(字符串处理)

Problem Description
Nowadays, Jim Green has produced a kind of computer called JG. In his computer, the instruction is represented by binary code. However when we code in this computer, we use some mnemonic symbols. For example, ADD R1, R2 means to add the number in register R1 and R2, then store the result to R1. But this instruction cannot be execute directly by computer, before this instruction is executed, it must be changed to binary code which can be executed by computer. Each instruction corresponds to a 16-bit binary code. The higher 6 bits indicates the operation code, the middle 5 bits indicates the destination operator, and the lower 5 bits indicates the source operator. You can see Form 1 for more details.
15 operation code(6 bits)109destination operator code(5 bits)54source operator code(5 bits)0Form 1


In JG system there are 6 instructions which are listed in Form 2.
instructionADD Ra,RbSUB Ra,RbDIV Ra,RbMUL Ra,RbMOVE Ra,RbSET RafunctionAdd the number in register Ra and Rb, then store the result to Ra.Subtract the number in register Ra to Rb, then store the result to Ra.Divide the number in register Ra by Rb, then store the result to Ra.Mulplicate the number in register Ra and Rb, then store the result to Ra.Move the number in register Rb to Ra.Set 0 to Ra.Form 2


Operation code is generated according to Form 3.
OperationADDSUBDIVMULMOVESETOperation code000001000010000011000100000101000110Form 3


Destination operator code and source operator code is the register code of the register which is related to.
There are 31 registers in total. Their names are R1,R2,R3…,R30,R31. The register code of Ri is the last 5 bits of the number of i in the binary system. For eaxample the register code of R1 is 00001, the register code of R2 is 00010, the register code of R7 is 00111, the register code of R10 is 01010, the register code of R31 is 11111.
So we can transfer an instruction into a 16-bit binary code easyly. For example, if we want to transfer the instruction ADD R1,R2, we know the operation is ADD whose operation code is 000001, destination operator code is 00001 which is the register code of R1, and source operator code is 00010 which is the register code of R2. So we joint them to get the 16-bit binary code which is 0000010000100010.
However for the instruction SET Ra, there is no source register, so we fill the lower 5 bits with five 0s. For example, the 16-bit binary code of SET R10 is 0001100101000000
You are expected to write a program to transfer an instruction into a 16-bit binary code or vice-versa.
 

Input
Multi test cases (about 50000), every case contains two lines.
First line contains a type sign, ‘0’ or ‘1’. 
‘1’ means you should transfer an instruction into a 16-bit binary code;
‘0’ means you should transfer a 16-bit binary code into an instruction.
For the second line.
If the type sign is ‘1’, an instruction will appear in the standard form which will be given in technical specification; 
Otherwise, a 16-bit binary code will appear instead.
Please process to the end of file.

[Technical Specification]
The standard form of instructions is 
ADD Ra,Rb
SUB Ra,Rb
DIV Ra,Rb
MUL Ra,Rb
MOVE Ra,Rb
SET Ra
which are also listed in the Form 2.
1a,b31
There is exactly one space after operation, and exactly one comma between Ra and Rb other than the instruction SET Ra. No other character will appear in the instruction.
 

Output
For type ‘0’,if the 16-bit binary code cannot be transferred into a instruction according to the description output “Error!” (without quote), otherwise transfer the 16-bit binary code into instruction and output the instruction in the standard form in a single line.
For type ‘1’, transfer the instruction into 16-bit binary code and output it in a single line.
 

Sample Input
  
  
1 ADD R1,R2 0 0000010000100010 0 1111111111111111
 

Sample Output
  
  
0000010000100010 ADD R1,R2 Error!
 


题意:就是有6个操作,分别有对应的二进制编码表示,看上面的表,然后只有1~31的数进行加减乘除,1用00001表示,31用11111表示

这里要你翻译编码的意思;例如样例1:

1

ADD R1,R2

1代表你要把Add换成000001  然后后面R1 1的编码  00001,R2的编码00010合起来就是  0000010000100010


第二组样例就是相反的意思



不得不说的是  一定要注意 SET 操作


好了,具体解释在代码中:



#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)
using namespace std;
#define N 1005

char op[10][10]={"ADD","SUB","DIV","MUL","MOVE","SET"};
char opp[10][10]={"000001","000010","000011","000100","000101","000110"};

char e[33][10]={"00000","00001","00010","00011","00100",     //请注意这个表很好,就是如果对应00011,那么就是下标3
				  "00101","00110","00111","01000","01001",
				  "01010","01011","01100","01101","01110",
				  "01111","10000","10001","10010","10011",
				  "10100","10101","10110","10111","11000",
				  "11001","11010","11011","11100","11101",
				  "11110","11111"};

char a[N],b[N],c[N];

int fdd(char *a)   //把Ra中的a取出来的函数
{
	int i,temp=0;
	int len=strlen(a);

	for(i=1;i<len;i++)
		temp=temp*10+a[i]-'0';
	return temp;
}

void solve()
{
	int i,j,pos;

	for(i=0;i<6;i++)
		if(strcmp(a,opp[i])==0)
		  break;
		pos=i;

	if(i==6)    //判断操作数是否合格
	{
		printf("Error!\n");
		return ;
	}
    if(i==5)     //如果是SET对应的000110 就单独处理
	{
		if(strcmp(c,e[0])!=0||strcmp(b,e[0])==0)   //必须满足c串对应的是0并且b串对应的数!=0,否者Error
		{
			printf("Error!\n");
		    return ;
		}
		for(i=1;i<32;i++)     
			if(strcmp(b,e[i])==0)
			break;
		printf("SET R%d\n",i);
		return ;
	}

	for(i=1;i<32;i++)
		if(strcmp(b,e[i])==0)
		break;
	j=i;
	for(i=1;i<32;i++)
		if(strcmp(c,e[i])==0)
		break;

		
    if(i>=32||j>=32)   //判断b,c串是否是e数组里的,换而言之是否合格(大于31就是不合格的)
	{
		printf("Error!\n");
		    return ;
	}
	printf("%s R%d,R%d\n",op[pos],j,i);
}

int main()
{
	int i,j,x;
	while(~scanf("%d",&x))
	{
		if(x==1)
		{
			scanf("%s%s",a,b);
			if(strcmp(a,op[5])==0)  //如果是SET单独处理
			{
				int pos=fdd(b);
				printf("%s%s00000\n",opp[5],e[pos]);
				continue;
			}
			int len=strlen(b);       //分成3段 a b c 分别代表  哪一种操作,Ra  Rb
			for(i=0;i<len;i++)
				if(b[i]==',')
				  break;
				b[i]='\0';
			j=0;
			i++;
			for(i;i<len;i)
				c[j++]=b[i++];
	        c[j]='\0';

	        for(i=0;i<6;i++)
				if(strcmp(a,op[i])==0)
				 break;
				 
			printf("%s",opp[i]);
			int pos;
			pos=fdd(b);

			printf("%s",e[pos]);
			pos=fdd(c);
			printf("%s\n",e[pos]);
		}
		else
		{
           scanf("%s",a);
           j=0;
           for(i=6;i<=10;i++)
			b[j++]=a[i];

		   j=0;
		   for(i;i<=15;i++)
			c[j++]=a[i];

		   a[6]='\0';
		   b[5]='\0';
		   c[5]='\0';

		   solve();
		}
	}

	return 0;

}



基于SSM框架的智能家政保洁预约系统,是一个旨在提高家政保洁服务预约效率和管理水平的平台。该系统通过集成现代信息技术,为家政公司、家政服务人员和消费者提供了一个便捷的在线预约和管理系统。 系统的主要功能包括: 1. **用户管理**:允许消费者注册、登录,并管理他们的个人资料和预约历史。 2. **家政人员管理**:家政服务人员可以注册并更新自己的个人信息、服务类别和服务时间。 3. **服务预约**:消费者可以浏览不同的家政服务选项,选择合适的服务人员,并在线预约服务。 4. **订单管理**:系统支持订单的创建、跟踪和管理,包括订单的确认、完成和评价。 5. **评价系统**:消费者可以在家政服务完成后对服务进行评价,帮助提高服务质量和透明度。 6. **后台管理**:管理员可以管理用户、家政人员信息、服务类别、预约订单以及处理用户反馈。 系统采用Java语言开发,使用MySQL数据库进行数据存储,通过B/S架构实现用户与服务的在线交互。系统设计考虑了不同用户角色的需求,包括管理员、家政服务人员和普通用户,每个角色都有相应的权限和功能。此外,系统还采用了软件组件化、精化体系结构、分离逻辑和数据等方法,以便于未来的系统升级和维护。 智能家政保洁预约系统通过提供一个集中的平台,不仅方便了消费者的预约和管理,也为家政服务人员提供了一个展示和推广自己服务的机会。同时,系统的后台管理功能为家政公司提供了强大的数据支持和决策辅助,有助于提高服务质量和管理效率。该系统的设计与实现,标志着家政保洁服务向现代化和网络化的转型,为管理决策和控制提供保障,是行业发展中的重要里程碑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值