编程介的小学生 2017-02-28 16:03 采纳率: 20.5%
浏览 790
已采纳

Hey, You're Not Marion Jones!

The Olympic committee has hired American Code Masters (ACM) to verify the IDs issued to all the athletes, reserves, judges, staff, and the press. Each badge has a barcode written on it in base-5, encoding the ID number. The system of ID numbers uses a check-digit scheme to detect errors and reduce forgeries. You are to write a program to help ACM detect invalid ID numbers.

The devices that security uses to read the barcodes produce strings of the letters V,W,X,Y,Z. Each letter represents a base-5 digit: V represents 4, W represents 3, X represents 2, Y represents 1, and Z represents 0. So, WXZ=320 (base-5), which is 85 (base-10). The base-5 number is first converted to a base-10 number. Any number with more than 8 (base-10) digits is considered invalid. Numbers with less than 8 digits are padded on the left with zeroes. IDs are allocated based on the most significant digit (in base-10):

0, 1 athletes;
2, 3 reserves,
4, 5 judges;
6, 7 staff; and
8, 9 press.

Consider the ID number d7 d6 ... d1 d0 expressed in base-10, where di (0 <= i <= 7) is a single digit of the ID number. For this ID to be valid the following checksum value must be 0:

F(0,d0) x F(1,d1) x F(2,d2) x ... x F(6,d6) x F(7,d7)

We will define the function F(i,j) and the operator next. The function F is defined as:

The definition of the function F depends on a permutation of the decimal digits we call G:

That is, G(0)=1, G(1)=5, etc.

The function i j is based on dihedral groups and has the nice property that transposing digits in the ID creates a checksum error. It is defined as follows:

Note that -4 mod 5 = 1.

The operator is left-associative, so for example i x j x k = (i x j) x k.

Input

The first line of the input contains an integer n >= 1. Each of the next n lines contains a single scanned barcode representing a potential ID number. Each scanned barcode will consist only of the characters 'V', 'W', 'X', 'Y', and 'Z' and will be at least 1 and at most 12 letters long.

Output

You should output the ID number as read, its corresponding base-10 number, and a message telling either that the ID is invalid or, if it is valid, the type of participant that the ID belongs to. Use the wording and format in the sample output below.

Sample Input

6
WYYXWVZXX
YWYWYYXWVZYY
YWYWYYXWVZYX
YYZWYYXWVZYX
YXXWYYXWVZXW
XYXWYYXWXYY

Sample Output

WYYXWVZXX/01274262 is valid athlete id number
YWYWYYXWVZYY/81352381 is valid press id number
YWYWYYXWVZYX/81352382 is invalid id number
YYZWYYXWVZYX/59868007 is valid judge id number
YXXWYYXWVZXW/73539888 is valid staff id number
XYXWYYXWXYY/22520431 is valid reserve id number

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-03-06 15:11
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)