【发布时间】:2021-08-20 22:00:26
【问题描述】:
char patern[]="AGAAGAG";
int n = strlen(patern);
int pat[n];
for (int i = 0; i < n; i++)
{
int j = 0;
while(j <= i )
{
if (patern.substr(0, j) == patern.substr(i-j+1, j))
{
pat[i] = j;
}
j++;
}
cout<<pat[i]<<endl;
}
我只能使用<iostream>、<cstring>、<cstdio>、<cstdlib>。输出为0011232。
【问题讨论】:
-
我不明白你的问题是什么。
-
char[]没有方法。你确定你没有使用std::string? -
@zead seam 另一种选择是 C 函数 strncmp。
-
@SilvioMayolo 如果我们用字符串 patern="AGAAGAG" 更改前两行;
-
@VladfromMoscow 谢谢
标签: c++ arrays char string-comparison c-strings