Code-11 is a barcode system for encoding characters used primarily in labeling telecommunications equipment. The characters encoded are limited to digits 0 through 9, the dash (“-”), and a special start/stop character which appears at the beginning and end of each Code-11 barcode.
    Code-11 is a discrete system, and each character is encoded independently. A character’s encoding is represented by five adjacent regions, or bars, that alternate between a dark color and a light color, starting with a dark bar. The width of each bar is either narrow or wide, according to the encoding scheme shown below, where 0 represents a narrow bar and 1 represents a wide bar.
Character Encoding
0 00001
1 10001
2 01001
3 11000
4 00101
5 10100
6 01100
7 00011
8 10010
9 10000
- 00100
Start/Stop 00110

    Thus the character 1 is encoded as a wide dark bar, a narrow light bar, a narrow dark bar, a narrow light bar, and finally a wide dark bar. The barcodes for the individual characters must be separated by a narrow light bar whose only function is to separate the characters.
    A two-width encoding like that used for Code-11 has the benefit of simplicity. Since it is necessary only to distinguish a narrow bar from a wide bar, Code-11 allows for a large level of print tolerance in lower-quality printing conditions.
    To enable detection of errors, the Code-11 barcodes we use will have two check characters, C and K, added at the end of the message (before the stop character). If the n characters to be encoded (left to right) are c1 through cn, then the weight of the C check character is

where w(ci) is the weight associated with character ci. The weights for the digits 0 through 9 are 0 through 9; the weight for the hyphen is 10. (Note that mod has higher precedence than +.)
    The weight of the K check character is

where cn+1 is the C check character. For example, suppose the message to be encoded is 123-45.
Then the C check character is 5 and the K check character is 2. The barcodes for the eight characters
123-4552, preceded and followed by the barcode for the start/stop character, comprise the complete
Code-11 barcode encoding of the message.
    Simple barcode readers measure the intensity of light reflected from a barcode to a linear array containing hundreds of tiny CCD sensors, each reporting light or dark. Light and dark regions are identified ,and the width of each region is used by the decoding software to validate the barcode and to obtain the encoded information. Since the orientation of the barcode is not fixed, the software must be able to decode the barcode whether it is scanned from left to right or from right to left.
    Your problem is to decode the information obtained by scanning a Code-11 barcode, given the widths of the light and dark regions detected by the reader. Assume a wide bar is intended to be twice as wide as a narrow bar. Due to inconsistencies among printers, the width of a bar can be up to 5 percent larger or smaller than intended. There are no zero-length messages (with barcodes containing only start/stop, check characters, and intercharacter spacing).
Input
The input contains several test cases, each representing a single scanning attempt. The data for each case begins with an integer m ≤ 150 that specifies the number of regions detected by a barcode reader. This is followed by m integers d1 . . . dm (1 ≤ di ≤ 200) giving the number of sensors in each region (within a region, all sensors report the same light intensity). The data for each test case begins and ends with a dark bar (there is no leading or trailing white space).
    The last test case is followed by a single integer zero.
Output
For each input case, display a line containing the case number and the results of the decoding effort. If the barcode can be successfully decoded, then display the sequence of message characters (without its check characters). If the decoding is successful but the C check character is incorrect, then display ‘bad C’. If the decoding is successful and the C check character is correct but the K check character is incorrect, then display ‘bad K’. Display ‘bad code’ if the barcode cannot be successfully decoded due to bar widths outside the allowable range, missing or invalid start/stop codes, or some other invalid condition. Follow the format of the sample output.
Sample Input
59
10 20 20 10 10 10 20 10 10 20
10 10 10 10 20 10 20 10 10 10
20 10 20 10 20 10 20 10 10 10
10 10 20 10 10 10 10 10 10 20
20 10 20 10 10 20 10 10 20 10
10 10 20 10 10 20 20 10 10

35
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10

35
10 10 20 20 10 10 20 10 10 10
20 10 10 20 10 10 20 10 10 10
20 10 20 10 20 10 10 10 10 10
10 10 20 20 10

0
Sample Output
Case 1: 123-45
Case 2: bad code
Case 3: bad K

World Finals >> 2010 - Harbin

问题链接:UVA1091 WF4786 Barcodes
问题简述:(略)
问题分析
    繁琐的条码检查和解码问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA1091 WF4786 Barcodes */#include<bits/stdc++.h>using namespace std;const string BADCODE = "bad code";
const int N = 200;
int n, a[N], b[N];
map<string, int> M;void init()
{M["00001"] = 0;M["10001"] = 1;M["01001"] = 2;M["11000"] = 3;M["00101"] = 4;M["10100"] = 5;M["01100"] = 6;M["00011"] = 7;M["10010"] = 8;M["10000"] = 9;M["00100"] = 10;M["00110"] = -1;
}string check()
{if(n % 6 != 5 || (n + 1) / 6 < 5) return BADCODE;int maxa = 0, mina = INT_MAX;for(int i = 0; i < n; i++) {maxa = max(maxa, a[i]);mina = min(mina, a[i]);}double t = (maxa + mina) / 2.0;maxa = 0, mina = INT_MAX;for(int i = 0; i < n; i++) {int tmp = a[i];if(tmp < t) tmp *= 2;maxa = max(maxa, tmp);mina = min(mina, tmp);}if(maxa * 95 > mina * 105) return BADCODE;string s;for(int i = 0; i < n; i++)s.push_back(a[i] < t ? '0' : '1');if(s.substr(0, 5) != "00110")reverse(s.begin(), s.end());if(s.substr(0, 5) != "00110") return BADCODE;int k = 0;for(int i = 0; i < n; i += 6) {if(i + 5 < n && s[i + 5] == '1')return BADCODE;if(!M.count(s.substr(i, 5)))return BADCODE;b[k++] = M[s.substr(i, 5)];}if(b[0] != -1 || b[k - 1] != -1) return BADCODE;for(int i = 1; i < k - 1; i++)if(b[i] == -1)return BADCODE;int m = k - 2, c = 0, d = 0;for(int i = 1; i <= m - 2; i++) {c += ((m - 2 - i) % 10 + 1) * b[i];c %= 11;}for(int i = 1; i <= m - 1; i++) {d += ((m - 1 - i) % 9 + 1) * b[i];d %= 11;}if(c != b[m - 1]) return "bad C";if(d != b[m]) return "bad K";string ret;for(int i = 1; i <=m - 2; i++)ret.push_back(b[i] == 10 ? '-' : '0' + b[i]);return ret;
}int main()
{init();int caseno = 0;while(~scanf("%d",&n) && n) {for(int i = 0; i < n; i++)scanf("%d", &a[i]);printf("Case %d: %s\n", ++caseno, check().c_str());}return 0;
}

UVA1091 WF4786 Barcodes【编码检查】相关推荐

  1. TFS文件编码检查机制和修改(Team Foundation Server 2013)

    TFS的版本控制系统会自动按照下面的标准检测代码文件的编码格式: 1. 首先,如果代码文件包含了BOM部分,则使用BOM中制定的编码格式打开文档 什么是BOM (Byte order mark)? h ...

  2. Android11.0(R) framework 新增类 lint 编码检查问题

    从 10.0 移植了几个类过来,没想到一编译出来几十个 errors,这就很离谱,明明是现成的代码. 后来仔细看了错误 log 提示,Your API changes are triggering A ...

  3. 【计算机网络】数据链路层 : 差错控制 ( 检错编码 | 差错来源 | 差错分类 | 冗余编码 )

    文章目录 一. 差错来源 二. 差错分类 三. 差错控制 四. "物理层" 编码 与 "数据链路层" 编码 对比 五. 冗余编码 一. 差错来源 "差 ...

  4. Objective-C开发编码规范

    针对自己的编码检查问题,改正为以下编码规范: 1. 协议( Protocols ) 在书写协议的时候注意用 <> 括起来的协议和类型名之间是没有空格的,比如 IPCConnectHandl ...

  5. Python | 多种编码文件(中文)乱码问题解决

    1 可以知道的是,文本文件的默认编码并不是utf8. 我们打开一个文本文件,并点击另存为 2 我们在新窗口的编码一栏看到默认编码是ANSI.先不管这个编码是什么编码,但是通过下拉列表我们知道,这种编码 ...

  6. linux对日语编码支持吗,linux nkf 日文编码转换命令

    对于日语的编码 windows : Shift-JIS Linux : 2.4内核使用EUC编码,2.6内核中使用UTF8编码 检查文件编码  nkf -g filename 通常处理字符编码都使用i ...

  7. linux nkf 日文编码转换命令[转载]

    对于日语的编码 windows : Shift-JIS Linux : 2.4内核使用EUC编码,2.6内核中使用UTF8编码 检查文件编码  nkf -g filename 通常处理字符编码都使用i ...

  8. 工程能力(2)代码的艺术编码惯例

    代码艺术 优秀代码标准: 代码的正确和性能 代码的可读和可维护性 代码的可运维和可运营 代码的可共享和可重用 系统设计要点: 清楚什么是系统架构 注意系统设计的约束 清楚需求是系统设计决策的来源 系统 ...

  9. linux nkf 日文编码转换命令

    对于日语的编码 windows : Shift-JIS Linux : 2.4内核使用EUC编码,2.6内核中使用UTF8编码 检查文件编码  nkf -g filename 通常处理字符编码都使用i ...

最新文章

  1. php根据单词截取英文语句,php按单词截取字符串的方法
  2. mysql 图片base64_关于图片的Base64编码
  3. j pocket_Wallabag:Pocket的开源替代品
  4. VMware VSphere 引发的学案(三)
  5. BZOJ 1106: [POI2007]立方体大作战tet 树状数组 + 贪心
  6. python遥感数据有偿处理_地质男转行学遥感Python——DMSP数据预处理二
  7. Matter over Wi-Fi: Raspberry Pi 4开发环境设置
  8. Scene Detection
  9. ALTREA cyclone IV e系列程序固化方法
  10. 一切皆是映射:浅谈操作系统内核的缺页异常(Page Fault)
  11. Python学习Scrapy天天美剧爬取数据、存储数据
  12. python爬取英雄联盟所有皮肤价格表_python 爬取英雄联盟皮肤并下载的示例
  13. 移动电源有哪些产品?热门的移动电源推荐
  14. 【PyTorch】保存和载入模型的两种方法
  15. 起重吊装资质证书如何办理通过?经验之谈
  16. python123.io同一个号可以同时在不同设备登陆吗-ITech8 - 合抱之木,生于毫末;九层之台,起于累土;千里之行,始于足下!...
  17. git常用命令+代码上传冲突+vscode拉取代码报would clobber existing tag错误
  18. 仿淘宝关闭二维码案例
  19. 多测师肖sir_高级金牌讲师_jenkins持续集成测试(001)
  20. 衣服、商品、商城网站模板首页,仿U袋网,vue+elementui简洁实现(二)

热门文章

  1. 树莓派+Kubernetes
  2. 开源GIS(十)——openlayers中加载在线标准与自定义切片
  3. IME输入法编程心得
  4. Go语言的复合数据类型struct,array,slice,map
  5. 用VC++建立Service服务应用程序
  6. pq 中m函数判断嵌套_你还在用IF函数进行逻辑判断吗?试试PQ,简单又实用
  7. python psutil.disk_python中psutil模块使用相关笔记
  8. Doris之Bitmap 索引
  9. java kafkastream_手把手教你写Kafka Streams程序
  10. 扩展-视图 View