0
点赞
收藏
分享

微信扫一扫

查找字符串中最长子串

左小米z 2022-06-14 阅读 121
int main()
{
string str="abc1234567890a123dabc123456bb";
int x=1;
int flag=0;
char temp[100]={0};
temp[0]=str[0];
int size=0;
for(int i=1;i<strlen(str.c_str());i++)
{
for(int j=0;j<strlen(temp);j++)
{
if(str[i]==temp[j])
{
flag=1;
break;
}
}
if(!flag)
{

temp[x++]=str[i];
if(size<strlen(temp))
size=strlen(temp);
}
else
{
x=1;
cout<<"i="<<i<<endl;
cout<<"temp="<<temp<<endl;
memset(temp,0,sizeof(temp));
temp[0]=str[i];
}
flag=0;
}
cout<<"size="<<size<<endl;

return 0;
}


举报

相关推荐

0 条评论