70,020
社区成员




char str[12]="123zxcvbnmgfryuyrh34756734zxcvbnm";
char sss[9][9];
bool tr = false;
int count=0;
for(int ii=0;ii<12;ii++)
{
for(int jj=ii+1;jj<12;jj++)
{
if(str[ii] == str[jj])
{
sss[ii][jj] = str[jj];
ii++;
count++;
tr = true;
}
else
{
if(tr == true)
{
ii=ii-count;;
jj=jj-count;
count=0;
tr=false;
}
}
}
}
char str[34]="123zxcvbnmgfryuyrh34756734zxcvbnm";
char sss[34][34];
bool tr = false;
int count=0;
for(int ii=0;ii<12;ii++)
{
for(int jj=ii+1;jj<12;jj++)
{
if(str[ii] == str[jj])
{
sss[ii][jj] = str[jj];
ii++;
count++;
tr = true;
}
else
{
if(tr == true)
{
ii=ii-count;;
jj=jj-count;
count=0;
tr=false;
}
}
}
}
#include "stdafx.h"
#include "string.h"
#include "malloc.h"
int main()
{
int i,j,k,t;
int max = 0;
char *p = NULL;
char str[42] = "2xtzuaojy5678zuaojy908pzuaojy417zuaojy356";
char temp[8];
char result[8];
memset(result,0,8);
p = str;
for(i=0;i <42;i++)
{
for(j=i+1;j <42;j++)
{
if(*(p+i)== *(p+j))
{
t = i;
k = 0;
memset(temp,0,8);
//只要找到了相同的首字符,就开始比较到没有相同的位置,记录当前字符串,看是否是最长的
while(*(p+t)== *(p+j))
{
temp[k] = *(p+t);//不断比较后续的字符
t++;
j++;
k++;
}
if(k > max)//将最长的字符串赋值给result
{
max = strlen(temp);
strcpy(result,temp);
}
}
}
}
//打印出结果在上述字符串中最长的是 "zuaojy"
printf("重复字符串最长的是 %s,长度为 %d \n",result,max);
return 0;
}