本文整理汇总了C++中SuffixTree::append方法的典型用法代码示例。如果您正苦于以下问题:C++ SuffixTree::append方法的具体用法?C++ SuffixTree::append怎么用?C++ SuffixTree::append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SuffixTree
的用法示例。
在下文中一共展示了SuffixTree::append方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
scanf("%s", buffer + 1);
n = strlen(buffer + 1);
SuffixTree *tree = new SuffixTree;
for (int i = 1; buffer[i]; i++) {
tree->append(buffer[i] - 'a' + 1);
} // for
tree->append(SuffixTree::EOFCHAR);
tree->sort(sa);
for (int i = 1; i <= n; i++) {
sa[i] = sa[i + 1];
} // for
for (int i = 1; i <= n; i++) {
rnk[sa[i]] = i;
} // for
int j = 0;
for (int i = 1; i <= n; i++) {
if (rnk[i] == 1)
continue;
j--;
if (j < 0)
j = 0;
while (buffer[sa[rnk[i]] + j] == buffer[sa[rnk[i] - 1] + j]) {
j++;
} // while
lcp[rnk[i]] = j;
} // for
for (int i = 1; i <= n; i++) {
printf("%d ", sa[i]);
} // for
printf("\n");
for (int i = 2; i <= n; i++) {
printf("%d ", lcp[i]);
} // for
printf("\n");
return 0;
} // function main
示例2: main
int main() {
// freopen("subst1.in", "r", stdin);
// freopen("subst1.out", "w", stdout);
scanf("%s", buf);
n = strlen(buf);
SuffixTree *tree = new SuffixTree;
for (size_t pos = 0; buf[pos]; pos++) {
tree->append(buf[pos] - 'A');
} // for
tree->append(EOFCHAR);
printf("%lld\n", tree->solve() - n - 1);
return 0;
} // function main