1574: Verify Credit Card

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:1 解决:1

题目描述

You are developing an application for online transactions and you want to accept several credit cards. Card numbers, however, are usually long, so it‘s easy to make mistakes when typing them in. You want to create a method that will verify the numbers entered by users. You know that the Luhn formula applies for all the acceptable card numbers. The Luhn formula works as follows. First, separate the individual digits of the credit card number. For example: 21378 becomes 2 1 3 7 8 If there is an even number of digits, multiply each digit in an odd position by 2. Otherwise, multiply each digit in an even position by 2. Positions are 1-indexed, so the first digit is at position 1. The example number above contains an odd number of digits, so we multiply each digit in an even position by 2: 2 1 3 7 8 becomes 2 2 3 14 8 Note that the even positions refer to the original number so they don‘t change even when a 2-digit number appears. Finally, take the sum of all the digits (for 2-digit numbers insert both the digits separately into the sum): 2+2+3+1+4+8 = 20 If the sum is a multiple of 10, the number is valid. Otherwise, it is invalid.

输入

You are given some string cardNumber containing the credit card number, one string per line. cardNumber will contain between 1 and 50 characters, inclusive. Each character in cardNumber will be a digit (‘0‘-‘9‘).

输出

For each string cardNumber, output "VALID" if the card number is valid, or "INVALID" if it is invalid (all quotes for clarity).

样例输入 复制

21378
31378

样例输出 复制

VALID
INVALID