---
# System prepended metadata

title: 'e910: 108 p10. 解碼問題'
tags: [Zerojudge]

---

# e910: 108 p10. 解碼問題
題目連結：[e910](https://zerojudge.tw/ShowProblem?problemid=e910)

這個我認為就是單純的難題
單純要測試輸入、判別的難題
尤其題目給定的代碼都與ASCII碼沒有關係

所以我用分類的方式減少判斷的難度

首先用長度的方式分類
長度決定呼叫的判斷函式

其中main以外函式皆為判斷的函式
以下為程式碼：

```c=
#include<stdio.h>
#include<string.h>

char c[1000000];

char check2(char a[100]){
	char ch0[1]={' '};
	char code0[3]={"00"};
	if(strcmp(a,code0)==0){
		return ch0[0];
	}else{
		return '=';
	}
}

char check4(char a[100]){
	int i;
	char codea[5] = {"1000"};
	char codee[7] = {"1111"};
	char codei[7] = {"0110"};
	char coden[7] = {"0111"};
	char codeo[7] = {"1001"};
	char codet[7] = {"1100"};
	char symb4[6] = {'A',
             'E',
             'I',
             'N',
             'O',
             'T'};
    if(strcmp(a,codea)==0){
    	return symb4[0];
	}else if(strcmp(a,codee)==0){
		return symb4[1];
	}else if(strcmp(a,codei)==0){
		return symb4[2];
	}else if(strcmp(a,coden)==0){
		return symb4[3];
	}else if(strcmp(a,codeo)==0){
		return symb4[4];
	}else if(strcmp(a,codet)==0){
		return symb4[5];
	}else{
		return '=';
	}
}


char check5(char a[100]){
  char codec[6]={"10110"};
  char coded[6]={"11010"};
  char codef[6]={"01010"};
  char codeh[6]={"10101"};
  char codel[6]={"10100"};
  char codem[6]={"01000"};
  char coder[6]={"11100"};
  char codes[6]={"11101"};
  char symb5[8] = {'C',
             'D',
             'F',
             'H',
             'L',
             'M',
             'R',
             'S'};
  if(strcmp(a,codec)==0){
    	return symb5[0];
	}else if(strcmp(a,coded)==0){
		return symb5[1];
	}else if(strcmp(a,codef)==0){
		return symb5[2];
	}else if(strcmp(a,codeh)==0){
		return symb5[3];
	}else if(strcmp(a,codel)==0){
		return symb5[4];
	}else if(strcmp(a,codem)==0){
		return symb5[5];
	}else if(strcmp(a,coder)==0){
		return symb5[6];
	}else if(strcmp(a,codes)==0){
		return symb5[7];
	}else{
		return '=';
	}
}

char check6(char a[100]){
	char codedot[7]={"010010"};
	char codeb[7]={"110110"};
	char codeg[7]={"010110"};
	char codep[7]={"010011"};
	char codeu[7]={"101111"};
	char codey[7]={"101110"};
  char symb6[6] = {'.',
             'B',
             'G',
             'P',
             'U',
             'Y'};
  if(strcmp(a,codedot)==0){
    	return symb6[0];
	}else if(strcmp(a,codeb)==0){
		return symb6[1];
	}else if(strcmp(a,codeg)==0){
		return symb6[2];
	}else if(strcmp(a,codep)==0){
		return symb6[3];
	}else if(strcmp(a,codeu)==0){
		return symb6[4];
	}else if(strcmp(a,codey)==0){
		return symb6[5];
	}else{
		return '=';
	}
}

char check7(char a[100]){
  char codew[8] = {"1101110"};
  char symb7[1] = {'W'};
  if(strcmp(a,codew)==0){
  	return symb7[0];
  }else{
  	return '=';
  }
}

char check8(char a[100]){
  char codepe[9]={"01011110"};
  char codev[9]={"11011111"};
  char symb8[2] = {',',
             'V'};
  if(strcmp(a,codepe)==0){
  	return symb8[0];
  }else if(strcmp(a,codev)==0){
  	return symb8[1];
  }else{
  	return '=';
  }
}

char check9(char a[100]){
  char code0[10]={"010111011"};
  char code1[10]={"110111100"};
  char code2[10]={"010111000"};
  char codek[10]={"010111111"};
  char codeq[10]={"010111001"};
  char symb9[5] = {'0',
             '1',
             '2',
             'K',
             'Q'};
             
	if(strcmp(a,code0)==0){
  	return symb9[0];
  }else if(strcmp(a,code1)==0){
  	return symb9[1];
  }else if(strcmp(a,code2)==0){
  	return symb9[2];
  }else if(strcmp(a,codek)==0){
  	return symb9[3];
  }else if(strcmp(a,codeq)==0){
  	return symb9[4];
  }else{
  	return '=';
  }
}

char check10(char a[100]){
  char code5[11]={"0101110101"};
  char codex[11]={"0101111101"};
  char symb10[2] = {'5',
             'X'};
  if(strcmp(a,code5)==0){
  	return symb10[0];
  }else if(strcmp(a,codex)==0){
  	return symb10[1];
  }else{
  	return '=';
  }
}

char check11(char a[100]){
	char codesup[12]={"01011101000"};
	char code3[12]={"11011110111"};
	char code6[12]={"11011110100"};
	char code7[12]={"01011101001"};
	char code8[12]={"11011110101"};
	char codej[12]={"01011111000"};
	char codez[12]={"11011110110"};
  char symb11[7] = {'!',
             '3',
             '6',
             '7',
             '8',
             'J',
             'Z'};
  if(strcmp(a,codesup)==0){
  	return symb11[0];
  }else if(strcmp(a,code3)==0){
  	return symb11[1];
  }else if(strcmp(a,code6)==0){
  	return symb11[2];
  }else if(strcmp(a,code7)==0){
  	return symb11[3];
  }else if(strcmp(a,code8)==0){
  	return symb11[4];
  }else if(strcmp(a,codej)==0){
  	return symb11[5];
  }else if(strcmp(a,codez)==0){
  	return symb11[6];
  }else{
  	return '=';
  }
  return '=';
}

char check12(char a[100]){
  char code4[13] = {"010111110011"};
  char symb12[1] = {'4'};
  if(strcmp(a,code4)==0){
  	return symb12[0];
  }else{
  	return '=';
  } 
}

char check13(char a[100]){
  char codequ[14]={"0101111100100"};
  char code9[14]={"0101111100101"};
  char symb13[2] = {'?',
             '9'};
  if(strcmp(a,codequ)==0){
  	return symb13[0];
  }else if(strcmp(a,code9)==0){
  	return symb13[1];
  }
  return '=';
}

int main(){
	while(scanf("%s",c)!=EOF){
		char code[100000];
		int n=0;
		int l=strlen(c),i,j;
		for(i=0;i<l;i++){
			char temp[20]={'6'};
			for(j=0;j<2;j++){ //2
				temp[j]=c[i+j];
			}
			if(check2(temp)!='='){
				code[n]=check2(temp);
				n+=1;
				i=i+1;
				//printf("i= %d\n",i);
				continue;
			}
			
			for(j=0;j<4;j++){  //4
				temp[j]=c[i+j];
			}
			if(check4(temp)!='='){
				code[n]=check4(temp);
				n+=1;
				i=i+3;
				//printf("i= %d\n",i);
				continue;
			}
			
			for(j=0;j<5;j++){  //5
				temp[j]=c[i+j];
			}
			if(check5(temp)!='='){
				code[n]=check5(temp);
				n+=1;
				i=i+4;
				//printf("i= %d\n",i);
				continue;
			}
			
			for(j=0;j<6;j++){  //6
				temp[j]=c[i+j];
			}
			if(check6(temp)!='='){
				code[n]=check6(temp);
				n+=1;
				i=i+5;
				//printf("i= %d\n",i);
				continue;
			}
			
			for(j=0;j<7;j++){  //7
				temp[j]=c[i+j];
			}
			if(check7(temp)!='='){
				code[n]=check7(temp);
				n+=1;
				i=i+6;
				//printf("i= %d\n",i);
				continue;
			}
			
			for(j=0;j<8;j++){  //8
				temp[j]=c[i+j];
			}
			if(check8(temp)!='='){
				code[n]=check8(temp);
				n+=1;
				i=i+7;
				//printf("i= %d\n",i);
				continue;
			}
			
			for(j=0;j<9;j++){  //9
				temp[j]=c[i+j];
			}
			if(check9(temp)!='='){
				code[n]=check9(temp);
				n+=1;
				i=i+8;
				//printf("i= %d\n",i);
				continue;
			}
			
			for(j=0;j<10;j++){  //10
				temp[j]=c[i+j];
			}
			if(check10(temp)!='='){
				code[n]=check10(temp);
				n+=1;
				i=i+9;
				//printf("i= %d\n",i);
				continue;
			}
			
			for(j=0;j<11;j++){  //11
				temp[j]=c[i+j];
			}
			if(check11(temp)!='='){
				code[n]=check11(temp);
				n+=1;
				i=i+10;
				//printf("i= %d\n",i);
				continue;
			}
			
			for(j=0;j<12;j++){  //12
				temp[j]=c[i+j];
			}
			if(check12(temp)!='='){
				code[n]=check12(temp);
				n+=1;
				i=i+11;
				//printf("i= %d\n",i);
				continue;
			}
			
			for(j=0;j<13;j++){  //13
				temp[j]=c[i+j];
			}
			if(check13(temp)!='='){
				code[n]=check13(temp);
				n+=1;
				i=i+12;
				//printf("i= %d\n",i);
				continue;
			}
			
			memset(temp,'\0',20);
		}
		for(i=0;i<n;i++){
			printf("%c",code[i]);
		}
		printf("\n");
		
	}
	return 0;
} 
```

例如字元長度2的只有 '0'
所以就建立一個判斷長度2函式：
```c=
char check2(char a[100]){
	char ch0[1]={' '};
	char code0[3]={"00"};
	if(strcmp(a,code0)==0){
		return ch0[0];
	}else{
		return '=';
	}
}
```
不過當然，這個程式碼還可以再優化
