Avoid ambiguous categories in an ordered list

Take a concrete example and hope that I can be clear. Suppose a (ordered) list of months:

January <February <March <... <December

(with integers that denote months based on zero), so

Jan = 0, Feb - 1, ..., Dec is 11.

Now suppose that I do not have access to the full name of the month, and I am given the following list, where the months were reduced to their first letter, and e denotes an empty category, for example:

e, F, e, e, e

If I create a list of “unambiguous months” (f: 1, s: 8, o: 9, n: 10, d: 11), I can fill in the empty categories by first calculating the first category (using subtraction and mod 12), and then write down the rest from there. However, suppose I am given a list

e, A, e, e, J, e

() , A ( , ), , Js, . , .

, , : (, ) ? / : , J, 11 e, J, 11 e... , J , .

. -, , , , O (mn). , , ( ), , KMP O (m + n), . .

+3
3

, , , KMP .

- . , J 11 e, .

, .

+5

- . , e, A, e, e, J, e.

: r = ".A..J."

c - :

  c = "JFMAMJJASONDJFMAMJJASOND"

r c, c.

, . , "JFMAMJJASOND", O(nm) , n - , m - ( JFMAMJJASOND).

+4

Il-Bhima . -, , A, M J J, , . . ( , .)

So, all you need from your entire start list is two months, the distance 12 is not 0 or 6. Then you can create a small regular expression to match the control lines. In addition, you can create a lookup table containing an ordered pair and the distance between the months.

+2
source

Source: https://habr.com/ru/post/1704230/


All Articles