编程介的小学生 2017-03-06 11:51 采纳率: 20.5%
浏览 812
已采纳

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-13 00:02
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格