13235 - GEC1506- Credit card security code (Advanced)   

Description

As credit card is so popular nowadays, the security of credit card is an important issue.

In this problem, you are asked to verify whether the credit card number and its security code match or not.

Input

The input contains

  1. One based number for security encoding; and
  2. One or more lines pairs for credit card information, where each line consists of  a pair of credit card numbers (separated by space) and  security code numbers

17

4024 7603 2331 3208,308
6011 1297 0941 1814,211

You are asked to verify these pairs by following rules:
(Take 1st pair as example)

1. Sum up all the credit card numbers.

4024+7603+2331+3208 = 17166

2. Encode the summed numbers using the following base-decimal format.
e.g.

base=17

17166 =  3 * 173 + 8 * 172 + 6*171 + 13 * 170

With this encoding method, 17166 is then encoded to 38613.

Note that in some cases, we may need more/less than the power of "3" times for the base number to encode.

Hint: You can get the power of the base number by following python code:

>>> result = 17  ** 2

>>>print(result)

289

>>> result = 17  ** 3

>>>print(result)

4913

 

3. The real security code number is the even position of the encoded number (Start from the right).

There are only 3 digits for a credit card security code.

From this example, an additional "0" is necessary to add in the beginning as we only get 2 digits (8 and 1).
The final verified security code is then found as these 3 digits (081).

In other words, if more than 3 digits you got, just keep the rightest 3 ones.
 

4. If the given security code (308) matches the one you encode (081), you return "correct", otherwise, "incorrect"

Output

The output is multiple lines of verification results based on given credit card pairs.

 

To solve this problem, except for the sys library for reading OJ input, you don't need any extra library by default.

Sample Input  Download

Sample Output  Download

Tags




Discuss