Вопрос

We are currently building a complicated financial report where every cell in the table is link to a group of accounts. Currently we will look at the group of a accounts and we manually figure out the filter/wildcards that defines that group. We need the filters to only include the accounts in the list. I was wondering if there a program to do this for us or is there an algorithm we can implement this. Also, all account numbers will be the same length.

Example:

Group A  
10004
10005
10006
21001
21023

Group B
10056
10055

Group C
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009

Group A would look like 1000[4,5,6], 21001, 21023

Group B would look like 1005[5,6]

Group C would look like 1000%

Это было полезно?

Решение

One solution that comes to mind is trie.

The general algorithm would be to find the longest prefix starting from the 1-st level(not 0-th level), fix this prefix and then append the different suffixes. Hope you will guess the next steps.

For example

Group A would look like 1000[4,5,6], 21001, 21023

Trie would look like

prefix tree

In this case the result is: 1000[4,5,6], 210[01,23]

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top