本帖最后由 匿名 于 2022-5-31 10:49 编辑
如果测试数据很大,但是map很小的话,可以先把map的模式展开,这样输入的string就能直接替换。
map展开可以用一个简单的循环搞定:先把mapping分成两类,有嵌套的和没有嵌套的。每次循环把有嵌套的进行一次展开,如果一次展开没有嵌套了则加入无嵌套集合,直到嵌套词汇集合为空结束循环。- Scan the map to get:
- NestedSet : contains word with %
- AtomSet: atomic word mapping
- While NestedSet is not empty:
- loop each item in this set
- loop each % word in this item to find a replacement, no need recursion
- check existence of % word of current item, if none then remove it from NestedSet, otherwise add it to the AtomSet
复制代码 |