//cpp
#include<iostream>
using namespace std;
#include"acb.h"
int main()
{
sqstr s1,t1,str;
input(s1,"adssdaxczefrcbxcvxqwgcxx");
input(t1,"sadxccxassdyii");
cout<<"s1:"; output(s1);
cout<<"t1:"; output(t1);
str=maxstr(s1,t1);
cout<<"str:";
output(str);
cout<<str.length<<endl;
return 0;
}
//acb.h
#define MaxSize 100 //串中的最多字符个数
typedef struct
{
char data[MaxSize];
int length;
}sqstr;
void input(sqstr &s, char str[]) //串的赋值运算
{
int i=0;
while (str[i]!='\0')
{
s.data[i]=str[i];
i++;
}
s.length=i;
}
sqstr maxstr(sqstr s,sqstr t)
{
sqstr str;
int midx=0,mlen=0,tlen,i=0,j,k;
while (i<s.length) //用i扫描串s
{
j=0; //用j扫描串t
while (j<t.length)
{
if(s.data[i]==t.data[j])
{
tlen=1;
for (k=1;i+k<s.length && j+k<t.length && s.data[i+k]==t.data[j+k];k++)
{
tlen++;
}
if (tlen>mlen) //将较大长度付给midx和mlen
{
midx=i; //记录当前相同字符串的下标
mlen=tlen; //记录当前相同字符串的长度
}
j=j+1;
}
else j++;
}
i++; // 继续扫描s中第i字符之后的字符
}
for (i=0;i<mlen;i++) //将最大公共子串复制到str中
{
str.data[i]=s.data[midx+i];
}
str.length=mlen;
return str; //返回最大公共子串
void output(sqstr s) //串的输出运算
{
int i;
for(i=0;i<s.length;i++)
cout<<s.data[i];
cout<<endl;
}
//--------------------Configuration: 1125 - Win32 Debug--------------------
Compiling...
1125.cpp
C:\Users\51207\Desktop\vC\11\1125.cpp(5) : error C2601: 'main' : local function definitions are illegal
C:\Users\51207\Desktop\vC\11\1125.cpp(17) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
1125.obj - 1 error(s), 0 warning(s)
c++中,求这两个串最大公共子串(求解为何报错)
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答
相关推荐 更多相似问题
点击登录
提问题
悬赏问题
- ¥15 使用DWY100k数据集对UEA进行测试,出现报错:IndexError: index 125000 is out of bounds for axis 0 with size 95500
- ¥15 前端vue实现根据图片url生成pdf文件
- ¥15 RfidReader资源Q个
- ¥20 user-agent是否是唯一的,有没有可能相同
- ¥15 关于#开会#的问题,如何解决?(语言-c++)
- ¥15 关于#二十四点问题#的问题
- ¥15 运行kitex的demon出错(求大家解决)
- ¥15 开发一个类似 typora 这样的软件需要多少钱?
- ¥15 clearcase7.0安装包
- ¥15 断点回归模型月度核密度检验不连续