TopCoder SRM 396 DIV 2

Problem Check Points
250 o 196.25
500 - -
1000 - -


500、とんでもない勘違いをしててうわぁぁあああ

@uwitenpen

Problem 250 VerifyCreditCard

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.

Given a String cardNumber containing the credit card number, return "VALID" if the card number is valid, or "INVALID" if it is invalid (all quotes for clarity).

問題文長くて辟易。
「偶数桁の場合は奇数番目を2倍」っていうのを見逃してて時間食った。

TopCoder SRM 396 DIV2 Problem250 VerifyCreditCard

Problem 500 DNAString

A string of length L is called periodic with period p if the i-th character is equal to the (i+p)-th character for all i between 0 and L-p-1, inclusive. For example, the strings "CATCATC", "CATCAT", "ACTAC" and "ACT" are all periodic with period 3.

You are given a String[] dna. Concatenate the elements of dna and return the minimum number of replacements needed to make the resulting string periodic with period less than or equal to maxPeriod. Each replacement consists of changing a single character from one letter to any other letter.

Stringの配列dnaは、自由に組み替えていいんだと思ってた。dnaの配列の個数は最大50。50!個の組み合わせなんてわかんないよー!って諦めてました。ただつなぐだけでいいです。

TopCoder SRM 396 DIV2 Problem500 DNAString