编程介的小学生 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 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿