编程介的小学生 2017-09-13 23:18 采纳率: 20.5%
浏览 776
已采纳

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

  • 写回答

1条回答

报告相同问题?

悬赏问题

  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能