시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 512 MB | 67 | 43 | 43 | 66.154% |
Mom Tihana wanted to buy her daughter Leda a plush toy via an online store. During the purchase process, the system asked for a credit card number to be entered. However, the purchase failed because Tihana mistakenly wrote one of the digits from that number. Internet research has revealed that such systems recognize the wrong number based on Luhn's algorithm.
This algorithm confirms the correctness of the number using a control digit which is always the last digit in the number. Steps to determine the validity of a number are:
E.g. account number 79927398713 is considered valid because the end right digit 3 can be obtained from the remaining digits in the way described.
Account number | 7 | 9 | 9 | 2 | 7 | 3 | 9 | 8 | 7 | 1 | 3 |
---|---|---|---|---|---|---|---|---|---|---|---|
Double every other | 7 | 18 | 9 | 4 | 7 | 6 | 9 | 16 | 7 | 2 | - |
Sum | 7 | 9 (1+8) | 9 | 4 | 7 | 6 | 9 | 7 (1+6) | 7 | 2 | = 67 |
(Sum after intermediate step · 9) mod 10 = (67 · 9) mod 10 = 603 mod 10 = 3 |
Write a program that loads the card number as a N-string that consists only of digits and exactly one sign "x", and prints the smallest one-digit number which we can replace the sign "x" with so that the account number is valid.
In the first line there is an integer number N (1 ≤ N ≤ 100), the length of string from the task's test. In the second line there is a string of length N consisting of just signs “0”, “1”, “2”, “3”, “4”, “5”, “6”, “7” , “8”, “9” and exactly one sign "x".
In the only line of the output it should be printed the required one-digit number.
11 7992739871x
3
5 x2464
5
10 93380x1696
1