70,037
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <bitset>
#include <map>
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
#include <string>
using namespace std;
const char* c128[] = {
"11011001100","11001101100","11001100110","10010011000","10010001100",
"10001001100","10011001000","10011000100","10001100100","11001001000",
"11001000100","11000100100","10110011100","10011011100","10011001110",
"10111001100","10011101100","10011100110","11001110010","11001011100",
"11001001110","11011100100","11001110100","11101101110","11101001100",
"11100101100","11100100110","11101100100","11100110100","11100110010",
"11011011000","11011000110","11000110110","10100011000","10001011000",
"10001000110","10110001000","10001101000","10001100010","11010001000",
"11000101000","11000100010","10110111000","10110001110","10001101110",
"10111011000","10111000110","10001110110","11101110110","11010001110",
"11000101110","11011101000","11011100010","11011101110","11101011000",
"11101000110","11100010110","11101101000","11101100010","11100011010",
"11101111010","11001000010","11110001010","10100110000","10100001100",
"10010110000","10010000110","10000101100","10000100110","10110010000",
"10110000100","10011010000","10011000010","10000110100","10000110010",
"11000010010","11001010000","11110111010","11000010100","10001111010",
"10100111100","10010111100","10010011110","10111100100","10011110100",
"10011110010","11110100100","11110010100","11110010010","11011011110",
"11011110110","11110110110","10101111000","10100011110","10001011110",
"10111101000","10111100010","11110101000","11110100010","10111011110",
"10111101110","11101011110","11110101110","10111011110","10111101110",
"11101011110","11010000100","11010010000","11010011100","1100011101011" };
#define ArrSize(x) (sizeof(x)/sizeof(x[0]))
int main()
{
const char* str = "1101001000010011100110110011100101100011101011";
map<unsigned long, int> c123_map;
// 将条码表存在map中
for(int i=0;i<ArrSize(c128);i++){
c123_map[bitset<16>(string(c128[i])).to_ulong()] = i;
}
// 根据输入字符串在条码表中查找相应的条码
while(strlen(str)>21){
string str1(str,11);
str+=11;
// 打印出当前匹配的条码在条码表中的位置
cout<<str1<<" -> "<<c123_map[bitset<16>(str1).to_ulong()]<<endl;
}
// 最后剩余的就是终止码
cout<<str<<" -> "<<c123_map[bitset<16>(string(str)).to_ulong()]<<endl;
return 0;
}
输出结果:
11010010000 -> 107
10011100110 -> 17
11001110010 -> 18
1100011101011 -> 109
char *c128[110] = {
"11011001100","11001101100","11001100110","10010011000","10010001100",
"10001001100","10011001000","10011000100","10001100100","11001001000",
"11001000100","11000100100","10110011100","10011011100","10011001110",
"10111001100","10011101100","10011100110","11001110010","11001011100",
"11001001110","11011100100","11001110100","11101101110","11101001100",
"11100101100","11100100110","11101100100","11100110100","11100110010",
"11011011000","11011000110","11000110110","10100011000","10001011000",
"10001000110","10110001000","10001101000","10001100010","11010001000",
"11000101000","11000100010","10110111000","10110001110","10001101110",
"10111011000","10111000110","10001110110","11101110110","11010001110",
"11000101110","11011101000","11011100010","11011101110","11101011000",
"11101000110","11100010110","11101101000","11101100010","11100011010",
"11101111010","11001000010","11110001010","10100110000","10100001100",
"10010110000","10010000110","10000101100","10000100110","10110010000",
"10110000100","10011010000","10011000010","10000110100","10000110010",
"11000010010","11001010000","11110111010","11000010100","10001111010",
"10100111100","10010111100","10010011110","10111100100","10011110100",
"10011110010","11110100100","11110010100","11110010010","11011011110",
"11011110110","11110110110","10101111000","10100011110","10001011110",
"10111101000","10111100010","11110101000","11110100010","10111011110",
"10111101110","11101011110","11110101110","10111011110","10111101110",
"11101011110","11010000100","11010010000","11010011100","1100011101011" };
char s[47]="1101001000010011100110110011100101100011101011"
char str1[12],str2[12],str3[12],str4[14];
int i,k1,k2,k3,k4;
strncpy(str1,s ,11);str1[11]=0;
strncpy(str2,s+11,11);str2[11]=0;
strncpy(str3,s+22,11);str3[11]=0;
strncpy(str4,s+33,13);str4[13]=0;
for (i=0;i<110;i++) if (0==strcmp(str1,c128[i])) break; k1=i;
for (i=0;i<110;i++) if (0==strcmp(str2,c128[i])) break; k2=i;
for (i=0;i<110;i++) if (0==strcmp(str3,c128[i])) break; k3=i;
for (i=0;i<110;i++) if (0==strcmp(str4,c128[i])) break; k4=i;